devxlogo

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

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

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.