c++visual-c++c++17string-literals

how to allow long Raw string literals to be compiled without separate resource files


I'm working on a C++ codebase which has been provided with some library's source files which I'm prevented from breaking some guidelines or changing the library logic and paradigms, for instance I'm not allowed to use resource files.

in the codebase source files there is a case which a very long raw string literal was used as following

constexpr auto kImGuiWS_js = R"(

    very long multiline string about 18000 characters

)";

and this causes some complications for example I get following error using MSVC compiler

Error   C2026    string too big, trailing characters truncated

which the documents indicate that

Before adjacent strings get concatenated, a string can't be longer than 16380 single-byte characters.

also there is a neat non-invasive solution for allowing normal long string literal to be compiled without change in code logic

char sz[] =
"\
imagine a really, really "
"long string here\
";

but this doesn't seem to be a possibility for raw string literals, are there any workarounds that could keep this code structure and allow me prevent compiler errors about exceeded long string literal maximum length?


Solution

  • but this doesn't seem to be a possibility for raw string literals

    It is:

    const char *foo = R"(abc)" R"(def)";
    

    https://godbolt.org/z/oEvcYfb9s