Is there any way to have multi-line plain-text, constant literals in C++, à la Perl? Maybe some parsing trick with #include
ing a file? I can't think of one, but boy, that would be nice. I know it'll be in C++0x.
C++ multiline string literal
cstring-literals
Related Topic
- C++ – Why is this program erroneously rejected by three C++ compilers
- C++ – Easiest way to convert int to string in C++
- C++ – Image Processing: Algorithm Improvement for ‘Coca-Cola Can’ Recognition
- C++ – Copy a file in a sane, safe and efficient way
- C++ – When should I really use noexcept
- C# – System.Windows.Application.GetResourceStream returns null
Best Answer
Well ... Sort of. The easiest is to just use the fact that adjacent string literals are concatenated by the compiler:
The indentation doesn't matter, since it's not inside the quotes.
You can also do this, as long as you take care to escape the embedded newline. Failure to do so, like my first answer did, will not compile:
Again, note those backslashes at the end of each line, they must be immediately before the line ends, they are escaping the newline in the source, so that everything acts as if the newline wasn't there. You don't get newlines in the string at the locations where you had backslashes. With this form, you obviously can't indent the text since the indentation would then become part of the string, garbling it with random spaces.