Monday, November 1, 2010

endl vs "\n"

Someone recently asked my why I used endl lines in place of "\n" must say I forgot that they are different. The key point is; Endl Forces a flush of the data stream as well as adding a new line. Where as "\n" is just a "raw" end of line.

A raw "\n" is used when you just need a new line and you dont care either way. IE User logs, data file writing, etc.

The idea usage of endl line is that the buffer is cleared in a timely fashion out the the user or stream. This is needed when the buffering may cause the unacceptable drag out of the final piece of data. IE networks, user prompts, etc

The other point to remember is that endl isn't always compatible with other libraries. For example boost lamba functions and Qt streams dont always react well to endl.

Of course unless your dumping thousands of lines here u shouldn't really have anywaycare.

No comments:

Post a Comment