The difference between "endl" and "\ n"

Possible duplicate:
C ++: "std :: endl" vs "\ n"

I am wondering if there is a significant difference between these two ways of printing a new line:

cout << endl;  //approach1
cout << "\n";  //approach2

Is there any practical difference?

+6
source share
1 answer

Yes, they are different.

"\n" is just a string of length 1 that is appended to stdout.

std::endl, instead, is an object that will add a newline character ( "\n") AND to flush the stdout buffer. For this reason, more processing is required.

+17
source

All Articles