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
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";
Just my 2 bobs worth...
I wouldn't wrap that line of code. I'd leave it as one big long string.
The 80 character convention was based on the limitations of the machinery of the day. Terminals where typically 80 by 32 characters. Cheap dot-matrix printers + continious-sheet paper was 80 characters. Only the rich people could afford a 132 character setup. And guess what... those who could afford it wrapped code at 132 characters, which dramatically decreases the number of lines which must be wrapped, and produces "cleaner" source code.
Those constraints don't apply today. My text editor displays 150 columns by 52 lines of 10pt courier new. My work monitors would display something like 400 by 65 (I've never tested it). I haven't printed a single line of source code in years... and the last time I did so was so that I could read it one the bus on the way home, when my laptop was on the fritz.
Modern langues are much more verbose than "older style" languages... and this is good. If you called anything a BeanContextServicesSupport.BCSSServiceProvider in Pascal your boss would have told you to go sit in the corner. Pascal identifiers where only significant to 8 characters!
So why persist with this outmoded and (to me) annoying convention? It makes very little practical sense.
So... I wrap "code lines" at 132 characters. I don't bother to wrap "text lines" at all.
See also: The width of two horses arses!
Cheers. Keith.
This will work on all the C++, weather it's VS, or on Linux
cout<<"Error:This is a really long error message that \
exceeds the maximum permitted length.\n";
cout << "Error:This is a really long error message "
"that does not exceed the maximum permitted length.\n";
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.