+ 3

Does endl and '/n' serve the same purpose?

22nd Dec 2015, 4:12 AM
Saksham Sneh
17 Respuestas
+ 8
It's almost the same.. but \n don't automatically flush the stream while endl does... This difference is not always significant in small and simple codes like the ones used in this tutorial but it's something you have to take into account.
8th Aug 2016, 4:06 AM
Nelson Urbina
Nelson Urbina - avatar
+ 5
(cout << endl;) and (cout << ”\n" << flush;) serve the same purpose.
17th Jan 2016, 1:06 PM
DJC
+ 2
it's "\n" by the way. Thanks
16th Jun 2016, 10:26 AM
Sheeshram
Sheeshram - avatar
+ 2
but endl jumps the cursor and flush te buffer so it's not the same thing
28th Aug 2016, 5:40 PM
Carlos Augusto Silva Gurgel
Carlos Augusto Silva Gurgel - avatar
+ 2
i think think it's no matter but i prefer \n one cz It's a little bit easy.
22nd Oct 2016, 1:33 AM
Shir Hussain
Shir Hussain - avatar
+ 1
yes but i think after cin >> u cant add /n u need to type cin << x << endl;
5th Jul 2016, 7:22 PM
Luda glista
Luda glista - avatar
0
"endl" and "\n" works d same. its Not "/n".
24th Jan 2016, 4:09 PM
Dhanusha
0
You should prefer "\n" over endl
19th Jun 2016, 2:23 PM
sonu
0
yes
22nd Oct 2016, 3:00 AM
Dzaki Alvriano
Dzaki Alvriano - avatar
0
yes, they are the same if we write endl it's a little bite easier than "\n" bcz it's need double quotation mark.
12th Nov 2016, 9:41 PM
Shir Hussain
Shir Hussain - avatar
0
yes
9th Dec 2016, 5:40 PM
Antara Rajgopal
Antara Rajgopal - avatar
- 1
yes. both moves the cursor to next line.
14th Jun 2016, 4:24 AM
MAZHAR IMAM KHAN
MAZHAR IMAM KHAN - avatar
- 2
yes it does
22nd Jun 2016, 11:27 AM
Sameer Zamiry
- 3
Yes, it does. They both start a new paragraph. For example: cout <<"Hello\nWorld!"; would be the same as cout <<"Hello" <<endl <<World!;
12th Apr 2016, 12:24 PM
Rocko
- 3
<<endl provides more neat code than \n
16th Jun 2016, 9:41 AM
Paul Fayvcay
Paul Fayvcay - avatar
- 3
(cout << endl;) and (cout << ”\n" << flush;) serve the same purpose.
23rd Jun 2016, 1:38 AM
gf fa
gf fa - avatar
- 5
Yes, but the 'std::endl' is platform-independent. That is, you can use it on windows too, whereas the '\n' would fail, cause '\0' is used on windows.
10th Jul 2016, 7:23 PM
Борис Кот
Борис Кот - avatar