Big line splitting

How do you say something like this?

static const string message = "This is a message.\n It continues in the next line" 

The problem is that the next line is not recognized as part of the line.

How to fix it? Or is it the only solution to create an array of strings and initialize the array to store each row?

+4
source share
3 answers

Include each line in your own set of quotes:

 static const string message = "This is a message.\n" "It continues in the next line"; 

The compiler will combine them into one line.

+16
source

You can use a trailing slash or quote each line this way

 "This is a message.\n \ It continues in the next line" 

or

 "This is a message." "It continues in the next line" 
+9
source

In C ++, as in C, string litterals separated by a space are implicitly concatenated, therefore

 "foo" "bar" 

is equivalent to:

 "foobar" 

So you want:

 static const string message = "This is a message.\n" "It continues in the next line"; 
+1
source

Source: https://habr.com/ru/post/1285688/


All Articles