What is Difference Between Endl and \n Statement in C++

Both the endl and '\n' are used to start a new line in C++ program, But there is a little difference between these two commands. N is a string of length 1 that get appended to namespace std . On the other hand endl flushes the buffer . In this case the main advantage of endl is that if the program crashed the stuff get printed.But if you are using just to jump in new line with endl it consume the processing power and reduce the efficiency of the program.

Source Code

#include<iostream>
using namespace std;
int main ()
{
 cout<<"\t \t \t LEP Tutorials \n \n \n ";
 cout<<" This New Line Start with Endl "<<endl<<endl ;
 cout<<"  This New Line Start with N \n \n ";
}

Output of the Program

ENDL AND \N STATEMENT IN C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment