By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,462 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

<< "\t";

P: n/a
just a quickie:

as
cout << endl;
is to
cout << "\n";

is there an equivalent for
cout << "\t";

??
Thanks
Mike
Jul 22 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
On Fri, 14 May 2004 15:46:29 +0000 (UTC) in comp.lang.c++, "Michael"
<sl***********@hotmail.com> wrote,
as
cout << endl;
is to
cout << "\n";

is there an equivalent for
cout << "\t";


No! And if there was, it would be even more evil than cout<<endl;

Jul 22 '05 #2

P: n/a

"Michael" <sl***********@hotmail.com> wrote in message
news:c8**********@hercules.btinternet.com...
just a quickie:

as
cout << endl;
is to
cout << "\n";

is there an equivalent for
cout << "\t";

??
Thanks
Mike


cout << endl; is not the same as cout << "\n"; because the first one besides
doing a new line, flushes the output as well
Jul 22 '05 #3

P: n/a

"David Harmon" <so****@netcom.com.invalid> wrote in message
news:40***************@news.west.earthlink.net...
On Fri, 14 May 2004 15:46:29 +0000 (UTC) in comp.lang.c++, "Michael"
<sl***********@hotmail.com> wrote,
as
cout << endl;
is to
cout << "\n";

is there an equivalent for
cout << "\t";


No! And if there was, it would be even more evil than cout<<endl;


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.

-Howard
Jul 22 '05 #4

P: n/a
"Michael" <sl***********@hotmail.com> wrote in message
news:c8**********@hercules.btinternet.com...
just a quickie:

as
cout << endl;
is to
cout << "\n";
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++).
is there an equivalent for
cout << "\t";

NB: again, prefer '\t'

How often does one want to flush the output
after writing a tab character ?

Regards,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Jul 22 '05 #5

P: n/a
"Howard" wrote:
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.


Why not something like:

#ifdef DEBUG
std::cout.rdbuf().setbuf(0,0);
#endif

?

Jul 22 '05 #6

P: n/a

"Marc" <Ma***********@Loria.Fr> wrote in message
news:c8***********@nef.ens.fr...
"Howard" wrote:
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.


Why not something like:

#ifdef DEBUG
std::cout.rdbuf().setbuf(0,0);
#endif

?


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.

Again...what's wrong with endl???

-Howard
Jul 22 '05 #7

P: n/a

"Michael" <sl***********@hotmail.com> wrote in message
news:c8**********@hercules.btinternet.com...
just a quickie:

as
cout << endl;
is to
cout << "\n";

is there an equivalent for
cout << "\t";

??
Thanks
Mike


No, but it's easy enough to write your own. Call it 'endt' say

#include <iostream>
using namespace std;

ostream& endt(ostream& os)
{
return os << '\t' << flush;
}

int main()
{
cout << "abc" << endt;
cout << "def" << endl;
}

john
Jul 22 '05 #8

P: n/a
"Howard" <al*****@hotmail.com> wrote in message
news:Aa*********************@bgtnsc05-news.ops.worldnet.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++.
So std::endl should be unnecessary, though not really evil IMO.

Regards,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form

Jul 22 '05 #9

P: n/a
"John Harrison" <jo*************@hotmail.com> wrote in message
news:2g************@uni-berlin.de

No, but it's easy enough to write your own. Call it 'endt' say

#include <iostream>
using namespace std;

ostream& endt(ostream& os)
{
return os << '\t' << flush;
}

int main()
{
cout << "abc" << endt;
cout << "def" << endl;
}

john

Nice. And if you don't really want the flushing, it is easier still.

#include <iostream>
using namespace std;

const char tab='\t';

int main()
{
cout << "abc" << tab;
cout << "def" << endl;
}
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)
Jul 22 '05 #10

P: n/a
"Michael" <sl***********@hotmail.com> schreef in bericht
news:c8**********@hercules.btinternet.com...
just a quickie:

as
cout << endl;
is to
cout << "\n";

is there an equivalent for
cout << "\t";

??
Thanks
Mike

std::endl is a function, not a character.
Jul 22 '05 #11

P: n/a
Ivan Vecerina wrote:
"Howard" <al*****@hotmail.com> wrote in message
news:Aa*********************@bgtnsc05-news.ops.worldnet.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++.


Where does the standard say that?
So std::endl should be unnecessary, though not really evil IMO.

Regards,
Ivan

Jul 22 '05 #12

P: n/a
"Jeff Schwab" <je******@comcast.net> wrote in message
news:hd********************@comcast.com...
Ivan Vecerina wrote:
"Howard" <al*****@hotmail.com> wrote in message
news:Aa*********************@bgtnsc05-news.ops.worldnet.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++.


Where does the standard say that?


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:
http://groups.google.com/groups?selm...nnrp1.deja.com
Thanks, and best regards,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Jul 22 '05 #13

P: n/a
Ivan Vecerina wrote:
"Jeff Schwab" <je******@comcast.net> wrote in message
news:hd********************@comcast.com...
Ivan Vecerina wrote:
"Howard" <al*****@hotmail.com> wrote in message
news:Aa*********************@bgtnsc05-news.ops.worldnet.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++.


Where does the standard say that?

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.


Why would that make it unlikely to be buffered? I've never seen a
situation in which cout was unbuffered.
Jul 22 '05 #14

P: n/a
"Jeff Schwab" <je******@comcast.net> wrote in message
news:S7********************@comcast.com...
Regarding cout, it is a bit more complicated... it is unlikely to
be buffered at the C++ level because by default it is supposed emphasis on: ~~~~~~~~~~~~~~~~ to be synchronized with stdout. But it can still be buffered.


Why would that make it unlikely to be buffered? I've never seen a
situation in which cout was unbuffered.


Please read the thread I refered to in my previous post:
http://groups.google.com/groups?selm...nnrp1.deja.com

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.

Regards,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form

Jul 22 '05 #15

P: n/a
Ivan Vecerina wrote:
"Jeff Schwab" <je******@comcast.net> wrote in message
news:S7********************@comcast.com...
Regarding cout, it is a bit more complicated... it is unlikely to
be buffered at the C++ level because by default it is supposed
emphasis on: ~~~~~~~~~~~~~~~~
to be synchronized with stdout. But it can still be buffered.
Why would that make it unlikely to be buffered? I've never seen a
situation in which cout was unbuffered.

Please read the thread I refered to in my previous post:
http://groups.google.com/groups?selm...nnrp1.deja.com

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).


That doesn't make it unbuffered; in fact, it generally means that cout
is buffered.
Because, on most platforms, cout is implemented in terms of stdout,
this means that buffering must be disabled in cout - at the C++ level.
Not sure what you mean. If you mean that the C++ run-time library may
not provide redundant buffering when the OS already provides a buffer
for stdout, then OK, I'm with you.
An implementation-defined buffering mechanism of stdout may still
apply, however.

Jul 22 '05 #16

P: n/a
"Jeff Schwab" <je******@comcast.net> wrote in message
news:Xc********************@comcast.com...
Ivan Vecerina wrote:
Because, on most platforms, cout is implemented in terms of stdout,
this means that buffering must be disabled in cout - at the C++ level.


Not sure what you mean. If you mean that the C++ run-time library may
not provide redundant buffering when the OS already provides a buffer
for stdout, then OK, I'm with you.


This is indeed what I meant by:
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.
Peace,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Jul 22 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.