Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Is there any MAJOR difference between \n and endl?

 
Post new topic   Reply to topic Printable version
 View previous topic  The Admin Cpanel - My version Post :: Post What about D?  View next topic  
Author Message
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:33
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Sun Aug 27, 2006 5:01 pm    Post subject: Is there any MAJOR difference between \n and endl? Reply to topic Reply with quote

Is there any difference between \n and endl? (Im talking about C++ btw.)

I don't really know if there is a difference that I should know about.

Anyone know if they are pretty much the same thing or not?
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Solo Ace
Yeah, I'm in touch with reality...we correspond from time to time.


Age:36
Gender:Gender:Male
Joined: Feb 06 2004
Posts: 2583
Location: The Netherlands
Offline

PostPosted: Sun Aug 27, 2006 5:19 pm    Post subject: Reply to topic Reply with quote

An std::endl would probably be printed as \n (or \r\n, no idea).

The major difference between those is (as I recall) that the endl causes the output stream to be flushed.

Simply explained, the output from your program is 'stored' in a buffer. This buffer is used to store the data temporarily until a specific ammount of data is collected. Then it is sent to its next destination.
The endl causes this buffer to be flushed.

It might be useful to use output buffering, it's efficient for larger pieces of data. But it only wastes time and memory if you want to print a bunch of lines and flush the output buffer every time.

I think that's it. And if someone thinks I'm wrong, please correct me. sa_tongue.gif My C++ book doesn't say anything about this, they simply use \n and say endl is the same.
Back to top
View users profile Send private message Add User to Ignore List
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:33
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Sun Aug 27, 2006 6:00 pm    Post subject: Reply to topic Reply with quote

Oh I see.

My book is the same way. sa_tongue.gif

Thanks for the info.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Dr Brain
Flip-flopping like a wind surfer


Age:38
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Sun Aug 27, 2006 11:30 pm    Post subject: Reply to topic Reply with quote

Not when you're just printing strings (Solo may be correct about the buffering, I don't personally know).

The use of endl is more apparent when you're printing things other than strings, and a \n can't easily be added to the end (and endl will be more efficient in those cases than a new string).
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Bak
?ls -s
0 in


Age:24
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Mon Aug 28, 2006 12:33 am    Post subject: Reply to topic Reply with quote

solo ace is correct about the buffering, but i've only noticed it when i was debugging someone's program in linux that was crashing. We added a bunch of print statements and if we didn't use endl or cout.flush(); (?), it wouldn't print them.
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:33
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Mon Aug 28, 2006 4:44 am    Post subject: Reply to topic Reply with quote

That sounds about right. does cout.flush have something to do with prevention of buffer overflows? (im taking a wild guess here. dont be too brutal)
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Solo Ace
Yeah, I'm in touch with reality...we correspond from time to time.


Age:36
Gender:Gender:Male
Joined: Feb 06 2004
Posts: 2583
Location: The Netherlands
Offline

PostPosted: Mon Aug 28, 2006 5:02 am    Post subject: Reply to topic Reply with quote

The only thing flushing the buffer does is make it pass the data to the next destination (the next library or whatever). Then the temporary buffer is cleared.

Uhm, this doesn't really have anything to do with a buffer overflow or the prevention of buffer overflows. For more information on buffer overflows check Wikipedia:Buffer overflow.
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Non-Subspace Related Coding All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 652 page(s) served in previous 5 minutes.

phpBB Created this page in 0.491399 seconds : 32 queries executed (84.4%): GZIP compression disabled