C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

'n' and flush cout

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
John Dill
Guest





PostPosted: Thu Oct 30, 2003 4:05 pm    Post subject: 'n' and flush cout Reply with quote



I am confused about why on certain compilers (gcc), inserting 'n'
causes std::cout to flush its contents to the screen. I thought the
whole point of using 'n' with std::cout was so that it wouldn't
flush. Is this behavior standard compliant? Why is it implemented
this way?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ben Hutchings
Guest





PostPosted: Fri Oct 31, 2003 2:47 am    Post subject: Re: 'n' and flush cout Reply with quote



In article <302c79f4.0310291510.607110de (AT) posting (DOT) google.com>,
John Dill wrote:
Quote:
I am confused about why on certain compilers (gcc), inserting 'n'
causes std::cout to flush its contents to the screen. I thought the
whole point of using 'n' with std::cout was so that it wouldn't
flush. Is this behavior standard compliant? Why is it implemented
this way?

If standard output is or may be attached to an interactive device, it
is line-buffered; otherwise it is fully buffered. (C99 specifies this
in section 7.19.3 paragraph 7; I believe C90 says the same, and C++98
incorporates C90 by reference.) So the buffer probably won't be
flushed after every line if you direct output to a file.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ron Natalie
Guest





PostPosted: Fri Oct 31, 2003 10:08 am    Post subject: Re: 'n' and flush cout Reply with quote




"John Dill" <john-dill (AT) uiowa (DOT) edu> wrote

Quote:
I am confused about why on certain compilers (gcc), inserting 'n'
causes std::cout to flush its contents to the screen. I thought the
whole point of using 'n' with std::cout was so that it wouldn't
flush. Is this behavior standard compliant? Why is it implemented
this way?

When the buffer flushes is up to the buffer. You can explicitly
flush it with a call to flush (or something that calls flush like
endl). The buffer is always free to flush earlier. Some
implementations will flush the buffer on 'n' when going to
a terminal device...this is consistant with what is also
allowed for the C stdio buffered output as well.



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Steven Binion
Guest





PostPosted: Sun Nov 02, 2003 5:17 pm    Post subject: Re: 'n' and flush cout Reply with quote

The only purpose I thought n had was for a new line, thats it.


--
Steven Binion
[email]stevenbinion (AT) the-binions (DOT) com[/email]
http://the-binions.com

AIM: stevebinion
MSN: [email]stevenbinion (AT) hotmail (DOT) com[/email]
Yahoo: stevenbinion
"John Dill" <john-dill (AT) uiowa (DOT) edu> wrote

Quote:
I am confused about why on certain compilers (gcc), inserting 'n'
causes std::cout to flush its contents to the screen. I thought the
whole point of using 'n' with std::cout was so that it wouldn't
flush. Is this behavior standard compliant? Why is it implemented
this way?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot 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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.