On Fri, 14 May 2004 15:46:29 +0000 (UTC) in comp.lang.c++, "Michael"
<slick_mick_00@ hotmail.com> wrote,
[color=blue]
>as
>cout << endl;
>is to
>cout << "\n";
>
>is there an equivalent for
>cout << "\t";[/color]
No! And if there was, it would be even more evil than cout<<endl;
"Michael" <slick_mick_00@ hotmail.com> wrote in message
news:c82pkl$7rk $1@hercules.bti nternet.com...[color=blue]
> just a quickie:
>
> as
> cout << endl;
> is to
> cout << "\n";
>
> is there an equivalent for
> cout << "\t";
>
> ??
> Thanks
> Mike
>
>[/color]
cout << endl; is not the same as cout << "\n"; because the first one besides
doing a new line, flushes the output as well
"David Harmon" <source@netcom. com.invalid> wrote in message
news:40c0ead7.8 3159306@news.we st.earthlink.ne t...[color=blue]
> On Fri, 14 May 2004 15:46:29 +0000 (UTC) in comp.lang.c++, "Michael"
> <slick_mick_00@ hotmail.com> wrote,
>[color=green]
> >as
> >cout << endl;
> >is to
> >cout << "\n";
> >
> >is there an equivalent for
> >cout << "\t";[/color]
>
> No! And if there was, it would be even more evil than cout<<endl;[/color]
What's evil about endl? I use it a lot. It's especially helpful when
debugging stuff, because it flushes the buffer and I know that there's
nothing in the stream that I can't yet see in my console window.
"Michael" <slick_mick_00@ hotmail.com> wrote in message
news:c82pkl$7rk $1@hercules.bti nternet.com...[color=blue]
> just a quickie:
>
> as
> cout << endl;
> is to
> cout << "\n";[/color]
First of all, one should prefer to use
cout << '\n' instead of cout << "\n"
(avoiding unnecessary pessimization).
Then, the purpose of endl is to end a line AND
flush the output buffer. It is equivalent to:
cout << '\n';
cout.flush();
This is useful in several logging or communication
protocols (although the console output streams,
by default, are not buffered in standard C++).
[color=blue]
> is there an equivalent for
> cout << "\t";[/color]
NB: again, prefer '\t'
How often does one want to flush the output
after writing a tab character ?
"Howard" wrote:
[color=blue]
> What's evil about endl? I use it a lot. It's especially helpful when
> debugging stuff, because it flushes the buffer and I know that there's
> nothing in the stream that I can't yet see in my console window.[/color]
"Marc" <MarcDotGlisse@ Loria.Fr> wrote in message
news:c82scj$141 d$1@nef.ens.fr. ..[color=blue]
> "Howard" wrote:
>[color=green]
> > What's evil about endl? I use it a lot. It's especially helpful when
> > debugging stuff, because it flushes the buffer and I know that there's
> > nothing in the stream that I can't yet see in my console window.[/color]
>
> Why not something like:
>
> #ifdef DEBUG
> std::cout.rdbuf ().setbuf(0,0);
> #endif
>
> ?
>[/color]
Why? It's a lot more work than using endl instead of '\n' (especially with
a lot of cout's being used), and you haven't given any indication as to what
if anything is wrong with endl.
Also, just because I'm "debugging" , doesn't mean it's a debug build. Often
times there are problems that only show up in release builds, and it helps a
lot to be sure that everything that was written to the stream was flushed to
the console prior to the problem occurring that I'm trying to solve.
"Michael" <slick_mick_00@ hotmail.com> wrote in message
news:c82pkl$7rk $1@hercules.bti nternet.com...[color=blue]
> just a quickie:
>
> as
> cout << endl;
> is to
> cout << "\n";
>
> is there an equivalent for
> cout << "\t";
>
> ??
> Thanks
> Mike
>[/color]
No, but it's easy enough to write your own. Call it 'endt' say
"Howard" <alicebt@hotmai l.com> wrote in message
news:Aa6pc.5758 9$Ut1.1517942@b gtnsc05-news.ops.worldn et.att.net...[color=blue]
> What's evil about endl? I use it a lot. It's especially helpful when
> debugging stuff, because it flushes the buffer and I know that there's
> nothing in the stream that I can't yet see in my console window.[/color]
Note: console I/O is unbuffered in standard C++.
So std::endl should be unnecessary, though not really evil IMO.
"Michael" <slick_mick_00@ hotmail.com> schreef in bericht
news:c82pkl$7rk $1@hercules.bti nternet.com...[color=blue]
> just a quickie:
>
> as
> cout << endl;
> is to
> cout << "\n";
>
> is there an equivalent for
> cout << "\t";
>
> ??
> Thanks
> Mike[/color]
Ivan Vecerina wrote:[color=blue]
> "Howard" <alicebt@hotmai l.com> wrote in message
> news:Aa6pc.5758 9$Ut1.1517942@b gtnsc05-news.ops.worldn et.att.net...
>[color=green]
>>What's evil about endl? I use it a lot. It's especially helpful when
>>debugging stuff, because it flushes the buffer and I know that there's
>>nothing in the stream that I can't yet see in my console window.[/color]
>
>
> Note: console I/O is unbuffered in standard C++.[/color]
Where does the standard say that?
[color=blue]
> So std::endl should be unnecessary, though not really evil IMO.
>
> Regards,
> Ivan[/color]
"Jeff Schwab" <jeffplus@comca st.net> wrote in message
news:hdqdnXmNIu _BqzXdRVn-ig@comcast.com. ..[color=blue]
> Ivan Vecerina wrote:[color=green]
> > "Howard" <alicebt@hotmai l.com> wrote in message
> > news:Aa6pc.5758 9$Ut1.1517942@b gtnsc05-news.ops.worldn et.att.net...
> >[color=darkred]
> >>What's evil about endl? I use it a lot. It's especially helpful when
> >>debugging stuff, because it flushes the buffer and I know that there's
> >>nothing in the stream that I can't yet see in my console window.[/color]
> >
> > Note: console I/O is unbuffered in standard C++.[/color]
>
> Where does the standard say that?[/color]
I slipped here, my comment was not totally correct.
cerr is unbuffered, and should indeed be used for debugging stuff.
Regarding cout, it is a bit more complicated... it is unlikely to
be buffered at the C++ level because by default it is supposed
to be synchronized with stdout. But it can still be buffered.
The following post/thread provides a description of the situation:
Ivan Vecerina wrote:[color=blue]
> "Jeff Schwab" <jeffplus@comca st.net> wrote in message
> news:hdqdnXmNIu _BqzXdRVn-ig@comcast.com. ..
>[color=green]
>>Ivan Vecerina wrote:
>>[color=darkred]
>>>"Howard" <alicebt@hotmai l.com> wrote in message
>>>news:Aa6pc.5 7589$Ut1.151794 2@bgtnsc05-news.ops.worldn et.att.net...
>>>
>>>
>>>>What's evil about endl? I use it a lot. It's especially helpful when
>>>>debugging stuff, because it flushes the buffer and I know that there's
>>>>nothing in the stream that I can't yet see in my console window.
>>>
>>>Note: console I/O is unbuffered in standard C++.[/color]
>>
>>Where does the standard say that?[/color]
>
>
> I slipped here, my comment was not totally correct.
>
> cerr is unbuffered, and should indeed be used for debugging stuff.
>
> Regarding cout, it is a bit more complicated... it is unlikely to
> be buffered at the C++ level because by default it is supposed
> to be synchronized with stdout. But it can still be buffered.[/color]
Why would that make it unlikely to be buffered? I've never seen a
situation in which cout was unbuffered.
"Jeff Schwab" <jeffplus@comca st.net> wrote in message
news:S7-dnbJoKZuG2TfdRV n-ig@comcast.com. ..[color=blue][color=green]
> > Regarding cout, it is a bit more complicated... it is unlikely to
> > be buffered at the C++ level because by default it is supposed[/color][/color]
emphasis on: ~~~~~~~~~~~~~~~ ~[color=blue][color=green]
> > to be synchronized with stdout. But it can still be buffered.[/color]
>
> Why would that make it unlikely to be buffered? I've never seen a
> situation in which cout was unbuffered.[/color]
Please read the thread I refered to in my previous post:
Unless the program calls std::ios_base:: sync_with_stdio (false),
it is possible to mix calls that write to stdout and cout with
the guarantee of a properly synchronized output.
I.e: cout<<'a'; putchar('b'); cout<<'c'<<endl ;
Is required to output "abc" (and not "bac" or anything else).
Because, on most platforms, cout is implemented in terms of stdout,
this means that buffering must be disabled in cout - at the C++ level.
An implementation-defined buffering mechanism of stdout may still
apply, however.
Comment