Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating a large string

Tags:

c++

string

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, the next line isn't being recognized as part of the string..

How to fix that? Or is the only solution to create an array of strings and then initialize the array to hold each line?

like image 626
Charles Khunt Avatar asked Nov 29 '22 00:11

Charles Khunt


2 Answers

Enclose each line in its 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 a single string.

like image 93
RichieHindle Avatar answered Dec 15 '22 06:12

RichieHindle


You can use a trailing slash or quote each line, thus

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

or

"This is a message."
"It continues in the next line"
like image 45
Alexander Torstling Avatar answered Dec 15 '22 06:12

Alexander Torstling