In c++ can we use \n as a new line character insted of endl | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

In c++ can we use \n as a new line character insted of endl

23rd Jun 2023, 3:27 PM
Kandukuri Harinayan
5 Answers
+ 5
Do not write irrelevant things like "upvote the question" in description. Add details to your question and add code related to it. Answer to your question is "yes, you can use both endl and \n in c++ and they serve same purpose of new line in your code. Refer to the example given here -> https://stackoverflow.com/questions/213907/stdendl-vs-n
23rd Jun 2023, 3:46 PM
D Shah 🎯⏳️
D Shah 🎯⏳️ - avatar
+ 3
Yes you can use \n instead of endl
23rd Jun 2023, 4:57 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
You can use "\n" instead of endl Difference is endl causes a buffer flush and \n do not In Competitive Coding \n is preferred over endl as buffer flush is slower
23rd Jun 2023, 7:28 PM
Virtual Pixel
Virtual Pixel - avatar
+ 2
If you need to flush the buffer use endl else use just \n
23rd Jun 2023, 8:01 PM
White Shadow
White Shadow - avatar
0
"\n" and "endl" both do the same they are twins.
25th Jun 2023, 8:40 AM
Alhaaz
Alhaaz - avatar