Command Line Text Formatter. Declaring a String

This topic is 3951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

NOTE: This problem is really a compiler issue rather than a programming problem. I am making a text formatter for a console program. Passing a string to my function works fine. However, if I declare a string like this:
std::string test = "Testing a string. blah blah blah blah blah blah blah blah
blah blah etc. etc";


I get error C2001 Newline in Constant. I could just declare the string out in one long statement(without word wrapping) like so:
[source lang= "cpp"]
std::string test ="Testing a string. blah blah blah blah blah blah blah blah blah blah etc. etc";


But this decreases readability. I hope this makes sense. Any suggestions?

Share on other sites
You could try creating two substrings and adding them together to form one large string. I don't see what the problem with leaving it on one line is, though.

Share on other sites
Just use a backslash to continue the statement on the next line

Edit: The example won't show up right. You need two separate sets of quotations, but the backslash at the end of the first line allows you to continue on the next one.

Share on other sites
Quote:
 Original post by skulldrudgeryJust use a backslash to continue the statement on the next lineEdit: The example won't show up right. You need two separate sets of quotations, but the backslash at the end of the first line allows you to continue on the next one.

Thank you. That works perfectly.

string text = "The quick brown fox "	"jumped over the lazy dog.";