0
\n and endl
Why cant we use \n instead of endl? I still do not get the difference.
5 Réponses
+ 7
You can use \n, but it has to be part of the string:
cout << "This is a string\n", not cout << "This is a string" << \n.
For the compiler, "\n" is just a regular ASCII character like "A", "J" or "quot;, so it has to be in quotation marks.
+ 5
endl prints new line and flushes the stream but \n only prints new line
cout << endl is equivalent to
cout << "\n" << flush
+ 4
I think you mean "\n" and they are used to do the same thing, it just depends on what one you prefer to use
+ 4
Their are not really same.... endl is a representation of newline on your platform than can be \n (Windows) or \r\n (Unix) for text files while using \n you will put into stream \n without taking cure of platform. Beside this, endl flush the stream opposite to \n
0
Yes! Sorry right \n. But when I replace endl with \n it shows error, why?