Jump to content
  • Advertisement
Sign in to follow this  
EnigmaticCoder

Command Line Text Formatter. Declaring a String

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by skulldrudgery
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.


Thank you. That works perfectly.

Share this post


Link to post
Share on other sites
Just so people know, there's another way you can do it:
string text = "The quick brown fox "
"jumped over the lazy dog.";

This automatically concatenates the two lines.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!