Public Group

# Compiler won't let me "put a newline in constant..." but I want to!

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

## Recommended Posts

haha, this is a pretty simple question. So, I have a REALLY long message box function (dialogue boxes aren't an option) and I want to put in on more than one line in the source code file. Example::
MessageBox(hWnd, "blah blah blah blah blah blah blah
blah blah", "blah", MB_OK);


But the compiler, VC .NET 7.1, won't let me... it gives me the error: new line in constant. Is there a way to break a constant char string onto more than one line in the source code? I don't want to have just one really long message box function on one line.... Thanks!

##### Share on other sites
MessageBox(hWnd, "blah blah blah blah"                 "blah blah blah blah", "blah", MB_BLAH);

##### Share on other sites
MessageBox(hWnd, "This is a really long"
" string which has no newlines", MB_OK);

MessageBox(hWnd, "This is a really long\n"
"string which has one newline", MB_OK);

MessageBox(hWnd, "strings" " " "are" " " "fun", MB_OK);

##### Share on other sites
MessageBox(hWnd, "blah blah blah blah blah blah blah "                  "blah blah", "blah", MB_OK);

You are right that the compiler do not accept newlines in constants, but it can concats litteral strings together.

(edit: and I'm again too slow. I'll cut the hands of Sneftel and uavfun.)

HTH,

##### Share on other sites
tried this way

MessageBox(hWnd, "Line1\nLine2\Line3", "3Lines", MB_OK);

??

should put out a msgBox with 3 lines of text

Line1
Line2
Line3

'\n' is ESC-char for newline, well i guess at least

correct me if iam wrong

##### Share on other sites
Ooooh! Just needed more double quotes. Thanks guys!

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46