I would like to define the content of a file in a wstring, so I can print it with an ofstream later on.
Example:
// Working
std::wstring file_content=L"€";
// Working
file_content=L"€"
L"€"
L"€";
// NOT Working
file_content=L"€"
L"€""
L"€";
// Working
file_content=LR"SOMETHING(multiline
with
no
issues)SOMETHING";
For some reason, the last solution is not working for me WHEN I paste in the file content (Multibyte).
Errors:
E0065 expected a ';'
E2452 ending delimiter for raw string not found
CodePudding user response:
You need to escape double-quote characters inside of a string literal, eg:
// Working
file_content=L"€"
L"€\"" // <--
L"€";
Alternatively, use a raw string literal instead, which does not require its characters to be escaped, eg:
// Working
file_content=L"€"
LR"(€")" // <--
L"€";
CodePudding user response:
std::wstring file_content=LR"SOMETHING(
€
€"
€
)SOMETHING";
Here, SOMETHING is something not found in the string and not required but it enables you to use " inside the multiline string literal without having to escape it.

