Endl does what? (C++) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Endl does what? (C++)

6th Oct 2017, 11:55 PM
Joe
5 Answers
+ 4
http://www.cplusplus.com/reference/ostream/endl/ "Inserts a new-line character and flushes the stream. Its behavior is equivalent to calling os.put('\n') (or os.put(os.widen('\n')) for character types other than char), and then os.flush()." The excess flush slows down your programs, so in many of my codes I only "endl" once -- at the end (+50% output or more) https://code.sololearn.com/cRjbtysU5r3o/?ref=app Same strategy applies to Python (there I gather all output in a variable, then print once)
7th Oct 2017, 12:29 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
So... it sounds like it adds a special character (that functions as a delimiter) that's equivalent of \n ("new line" function) and then a flush (syncing of internal stream data with external) and slow-downs come from the syncing because it has to read all data stream and that takes the time (and above 4000 characters takes more time)
7th Oct 2017, 1:01 AM
Joe
0
Found my answer by tapping on the text. Turns out the UI in SoloLearn will show you "hints" aka descriptions if you press on an underlined text within program examples. Such as the C++ "Working with Variables" section. If someone has a technical answer of what endl does under the hood, or just needs a question to answer, it would still be appreciated :D It was stated as a macro for \n (in a different answer to a related question) Can someone elaborate? (My apologies if this is a duplicate question)
6th Oct 2017, 11:59 PM
Joe
0
Adds a specific symbol, which is interpretered as next line of text. ASCII table has the code for this symbol, but I can't remember it.
7th Oct 2017, 12:27 AM
Freezemage
Freezemage - avatar
0
*interpreted as delimiter for lines of text Sorry, my mistake.
7th Oct 2017, 12:29 AM
Freezemage
Freezemage - avatar