From: Alona on
Is there a C++ analog for setvbuf()? Is there a way to set line
buffering for stdout other than calling 'endl' ?

As I understand, cout is line buffered for as long as the output goes
to a terminal device. cout becomes fully buffered as soon as it loses
terminal. Will 'endl' ensure line buffering for an application which
runs whithout terminal or something like setvbuf() is required?

Thank you,
Alona

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

From: Stephen Howe on
On Tue, 8 Dec 2009 05:16:05 CST, Alona <arossen(a)rogers.com> wrote:

>Is there a C++ analog for setvbuf()?

stream.rdbuf()->pubsetbuf(buffer, size);

where "buffer" is an actual buffer (or NULL) and size is size of buffer (or 0 if no buffering is wanted).

Stephen Howe

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

From: Alona on
On Dec 8, 9:22 pm, Stephen Howe
<sjhoweATdialDOTpipexDOT...(a)giganews.com> wrote:
> On Tue, 8 Dec 2009 05:16:05 CST, Alona <aros...(a)rogers.com> wrote:
> >Is there a C++ analog for setvbuf()?
>
> stream.rdbuf()->pubsetbuf(buffer, size);
>
> where "buffer" is an actual buffer (or NULL) and size is size of
> buffer (or 0 if no buffering is wanted).

{ edits: quoted sig & banner removed, extremely long line wrapped. please don't
quote signatures or the banner (which is added to every article). -mod }

1) Should 'stream.rdbuf()->pubsetbuf(buffer, size)' be called if we
call 'endl'? Does 'endl' ensure line buffering when app runs without a
terminal?

2)Our application is C++ and we only use C++ input/output functions.
However, we use 3rd party libraries that still call printf().
Can we call setvbuf() for a C++ app to ensure line buffering for printf
() called from 3rd party libs?

Thanks,
Alona


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

From: Frank Birbacher on
Hi!

Alona schrieb:
> Will 'endl' ensure line buffering for an application which
> runs whithout terminal or something like setvbuf() is required?

std::endl will output a newline and then flush the stream. Thus it will
always output this line then. Furthermore cout and cin are tied and
whenever you read from cin, cout will be flushed. You can also call
cout.flush directly or do cout << std::flush to flush the stream manually.

Frank

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

From: Frank Birbacher on
Hi!

Alona schrieb:
> 1) Should 'stream.rdbuf()->pubsetbuf(buffer, size)' be called if we
> call 'endl'?

I don't think you should call pubsetbuf at all. It will not really help
with line buffering.

> Does 'endl' ensure line buffering when app runs without a
> terminal?

Yes.

> Can we call setvbuf() for a C++ app to ensure line buffering for printf
> () called from 3rd party libs?

cout and printf mix well. You can call cout.flush() in order to flush
out messages from printf.

Frank

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