Jump to content
  • Advertisement
Sign in to follow this  
heron3d

declaring character array that does not fit in one single line

This topic is 3666 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

Hi I have a character array that is too long to fit in one line. How can I declare the array with multiple lines of letters? N

Share this post


Link to post
Share on other sites
Advertisement
C/C++ will auto-concatenate string literals without operators between them:


std::string s1 = "Hello"
" world!"; // one line

std::string s2 = "Hello world!\n"
"How is everyone?"; // two lines

Share this post


Link to post
Share on other sites
Please also note that you are not talking about "character arrays"; you are talking about "string literals". Only the double-quoted strings get this treatment - not variables, even if those variables hold "strings" (of any sort).

Share this post


Link to post
Share on other sites
how about if I'm using

char myString[] = "declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other. declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other. declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other.";

n

Share this post


Link to post
Share on other sites
Quote:
Original post by heron3d
how about if I'm using

char myString[] = "declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other. declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other. declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other.";

n


EDIT: The '\' character breaks source/code boxes :(

Use the '\' character to just basically split one line into as many as you wish. The next lines will be literally concatenated as is.

Share this post


Link to post
Share on other sites
Quote:
Original post by heron3d
how about if I'm using

char myString[] = "declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other. declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other. declaring character array that does not fit in one single line ends up creating more lines in the text editor because the line wraps around from one end to the other.";

n

Text wrapping in a text editing box has nothing to do with its contents. If you haven't pressed enter to go to a new line then its still one line. You editor simply continues displaying the line on the next line so that you don't have to scroll across.

Otherwise as previously mentioned you can split up the string.

char myString[] = "Hello, my name's Bob and I "
"went to the circus today.\n\n" // these add new-line characters to the string but separating double quotes on different lines does not
"Then I went to the shop to buy a sausage roll and tomato sauce."


The compiler will concatenate the adjacent string literals into:
char myString[] = "Hello, my name's Bob and I went to the circus today.\n\nThen I went to the shop to buy a sausage roll and tomato sauce."

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!