funtion problem?

Started by
10 comments, last by ApochPiQ 17 years, 1 month ago
Quote:Original post by NUCLEAR RABBIT
2) how much text should i wait for to use 'std::endl'?


A logical "block". Which is to say, from the time that you start sending stuff to endl until the time you're done - without anything else in between - don't use it.

Quote:Original post by ApochPiQ
The best thing to do is just use endl where you normally would, and if it becomes a performance concern, then consider only using "\r\n" and sending a flush (or endl) less often. If it isn't causing performance problems, don't worry about it.


My argument is not based on performance. It is based on the idea that '\n' is just another character; it isn't special, so there's no reason to treat it differently from every other character (by giving it a special name and outputting it always as a separate item). That adds verbosity to the code without meaning.

If you want to emphasize the line breaks, you can split your strings after the \n's:

cout << "The Interesting Paragraph\n""What on earth is going on here? I thought this was going to be an\n""INTERESTING paragraph. Instead it's full of all this filler text. By\n""the way, you might notice here that there aren't any extra <<'s for each\n""text string. What's going on is that the preprocessor will join up adjacent\n""string literals (literals ONLY, i.e. double-quoted text) ahead of time, so\n""all of this is actually really only one string being sent to cout." << endl;


(Of course, you are free to output the lines as separate items, too, and if you are inserting numbers into the output or something, then you certainly will need a few extra <<'s here. Consistency is a virtue in the same way as avoiding redundancy; some discretion is required.)
Advertisement
I have to admit that I don't do much in console-land, so I hadn't really thought about it; but the idea of preferring \n over endl to avoid semantic debris is a good point.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement