Reputation: 537
I want to write a string and press "Enter" while continuing writing this string, without having to close the "".
For example, i want to write the following line:
string drawing = "\\n\\n" +
"W W W " +
"\\nW W W W " +
"\\n '. W ";
but when i tried to do so, the compiler complains this:
error: invalid operands of types ‘const char [5]’ and ‘const char [23]’
to binary ‘operator+’
Is there a nice way to enter a new line without concating the string (like there is in python, for example, with entering the '\')?
Thanks.
Upvotes: 0
Views: 278
Reputation:
Try it without "+".
string drawing = "\n\n"
"W W W "
"\nW W W W "
"\n '. W ";
Upvotes: 5
Reputation: 139840
In C++, when you have two or more string literals only separated by whitespace, they get concatenated. So you can use
string drawing = "\n\n"
"W W W "
"\nW W W W "
"\n '. W ";
Upvotes: 1
Reputation: 4779
You end the string with a backslash:
std::string drawing = "\n\n\
W W W \
\nW W W W \
\n '. W ";
Upvotes: 3