Is std :: endl OS dependent?

Possible duplicate:
What does std :: endl mean exactly on each platform?

I'm trying to figure out if std :: endl will return \r\n

, \n

or \r

depending on the platform, or if it stays alone all the time.

+3


source to share


2 answers


std::endl

is just "shorthand" for '\n' << std::flush

. It is platform independent.



However, itself is '\n'

handled differently on each platform and is replaced with '\r\n'

, '\n'

or '\r'

(or something like that) if the stream is opened in text mode.

+13


source


'\ n' Outputs a newline (in the appropriate platform-specific representation, so it generates "\ r \ n" on Windows). std :: endl does the same and dumps it.



Use '\ n' instead of std :: endl; when trying to output a newline, but use std::endl

when trying to dump it. Unnecessary cleanup slows down the performance of your application as we all know that file i / o is one of the slowest operations besides user I / O.

+2


source







All Articles