Difference Between endl and ‘ ‘

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


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist