press 'Enter' in the middle of writing a string in c++
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.
Try it without "+".
string drawing = "\n\n"
"W W W "
"\nW W W W "
"\n '. W ";
You end the string with a backslash:
std::string drawing = "\n\n\
W W W \
\nW W W W \
\n '. W ";
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 ";
精彩评论