hi, sorry if this is too noob a question but what exactly does endl do? i notice it used alot at the end of cout but it isnt always used
thanks for any help
hi, sorry if this is too noob a question but what exactly does endl do? i notice it used alot at the end of cout but it isnt always used
thanks for any help
endl places a newline in the buffer and then flushes the buffer.
ah i see, cool thanks.
I suggest that you use "\r\n" or "\n" instead of endl, it's cleaner and shorter.
> I suggest that you use "\r\n" or "\n" instead of endl, it's cleaner and shorter.
But they don't guarantee that the output stream will be flushed, unlike endl.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
endl has it's place. for example, take a look at this:in that example, the speed won't be noticable, but if you have alot of output, you'll definately notice the difference. The first example is the most efficient of the three because there's no need to flush the buffer every line, unless you're worried about some kind of error occurring in the middle of that block that would halt output. In that case, you should probably be using unbuffered (cerr) output.Code:/* This */ std::cout<<"lorem ipsum dolor sit amet\n" <<"consectetuer adipiscing elit.\n" <<"Integer vel nibh eu mi iaculis facilisis."<<std::endl; /* Is faster than this */ std::cout<<"lorem ipsum dolor sit amet"<<std::endl <<"consectetuer adipiscing elit."<<std::endl <<"Integer vel nibh eu mi iaculis facilisis."<<std::endl; /* Which is faster than this */ std::cout<<"lorem ipsum dolor sit amet"<<std::endl std::cout<<"consectetuer adipiscing elit."<<std::endl std::cout<<"Integer vel nibh eu mi iaculis facilisis."<<std::endl;
Last edited by major_small; 10-19-2005 at 11:06 AM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
thank you very much ,
major_small
That was a new piece of information for me!!
You should worry about getting it working before trying to make it faster/smaller
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.