Endl is for what propose??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Endl is for what propose???

9th Jan 2018, 4:17 PM
Kumar Tushar
Kumar Tushar - avatar
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.
9th Jan 2018, 4:30 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
ending of that line ..which makes the next statements to be start from new line
9th Jan 2018, 4:30 PM
NAGANDLA.LEELA PAVAN KUMAR
NAGANDLA.LEELA PAVAN KUMAR - avatar
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'
9th Jan 2018, 4:29 PM
Ice
Ice - avatar
0
thanks very much guys..... you guys helped me very well...
9th Jan 2018, 5:09 PM
Kumar Tushar
Kumar Tushar - avatar