- 1
Endl is for what propose???
4 Answers
+ 9
endl appends '\n' to the stream andcalls flush() on the stream. So
cout << x << endl;
is equivalent to
cout << x << '\n';
cout.flush();
A stream may use an internal buffer which gets actually streamed when the stream is flushed. In case of cout you may not notice the difference since it's somehow synchronized (tied) with cin, but for an arbitrary stream, such as file stream, you'll notice a difference in a multithreaded program,Â
endl is more than just an alias for the \ncharacter. When you send something to cout (or any other output stream), it does not process and output the data immediately. For example:
cout << "Hello, world!"; someFunction();
In the above example, there's is somechance that the function call will start to execute before the output is flushed. Using endl you force the flush to take place before the second instruction is executed. You can also ensure that with the ostream::flush function.
+ 1
ending of that line ..which makes the next statements to be start from new line
0
to seperate a line in c++.
If you type like this:
cout << "Hello ";
cout <<"World";
The result will be 'Hello World'
But if your code is like this:
cout << "Hello"<<endl;
cout << "World";
The result will be like:
'Hello'
'World'
0
thanks very much guys..... you guys helped me very well...