[CSI] endl vs \n
Mikhail Nesterenko
mikhail at cs.kent.edu
Sat Jun 6 17:08:08 EDT 2020
>
> I was wondering what is the difference between these 2 programs and where
> each one would be better in certain applications or if one is better than
> the other.
>
endl inserts end of line character that forces further output and
input to go to the next line. This character is "\n"
endl needs to be outside of a string.
cout << endl;
and
cout << "\n";
are equivalent. I tend to use endl when output preceeding it is not a
string and \n otherwise. For example:
int i = 55;
cout << i << endl; // endl is used
cout << "Hello, World!\n"; // \n is used
More on this on Wednesday!
--
Mikhail
More information about the cs13001
mailing list