Difference Between endl and ‘ ‘

Take a look at the following code:

#include int main(){  int i = 12;  std::cout << i << '
'; // A  std::cout << i << std::endl; // B  return 0;} 

Using '
'
is a request to output a newline. Likewise, using endl requests to output a newline, but it also flushes the output stream. In other words, endl has the same effect as (ignoring the std:: for now):

 cout << i << '
'; // C: Emit newlinecout.flush(); // Then flush directly 

Or this:

 cout << i << '
' << flush; // D: use flush manipulator 

It's worth pointing out that these are different too:

cout << i << '
'; // E: with single quotescout << i << "
"; // F: with double quotes 

Note that Es last output request is for a char, hence operator Fs case, the last is a const char[2], and so operator

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: