How to split long lines of code in c++?


Question

I need to make sure none of the lines in my code exceeds a a certain length.

Normally I separate lines where there's a comma or another suitable break.

How can I separate this line into 2?

cout<<"Error:This is a really long error message that exceeds the maximum permitted length.\n";

If I just press enter somewhere in the middle it doesn't work.

1
30
10/23/2012 8:37:04 AM

Accepted Answer

Two options:

cout << "Error:This is a really long "
 << "error message that exceeds "
 << "the maximum permitted length.\n";

Or:

cout << "Error:This is a really long "
    "error message that exceeds "
    "the maximum permitted length.\n";

The second one is more efficient.

43
6/9/2009 11:08:59 AM

cout<<"Error:This is a really long error "
"message that exceeds the maximum permitted length.\n";

or

cout<<"Error:This is a really long error \
message that exceeds the maximum permitted length.\n";

or

c\
o\
u\
t<<"Error:This is a really long error \
message that exceeds the maximum permitted length.\n";

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon