| View previous topic :: View next topic |
| Author |
Message |
John Dill Guest
|
Posted: Thu Oct 30, 2003 4:05 pm Post subject: 'n' and flush cout |
|
|
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
|
Posted: Fri Oct 31, 2003 2:47 am Post subject: Re: 'n' and flush cout |
|
|
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
|
Posted: Fri Oct 31, 2003 10:08 am Post subject: Re: 'n' and flush cout |
|
|
"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
|
Posted: Sun Nov 02, 2003 5:17 pm Post subject: Re: 'n' and flush cout |
|
|
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 |
|
 |
|