473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

<< "\t";

just a quickie:

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

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

??
Thanks
Mike
Jul 22 '05 #1
16 2055
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

"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

"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
"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
"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

"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

"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
"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
"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
"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
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
"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
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String...
2
by: J.D. Buehls | last post by:
I am displaying some values on a report. I am opening the .asp page with a Response.ContentType = "application/msword" and these particular values appear in a table. One column shows percentages...
1
by: Serguei | last post by:
Dear Experts, I try to use a < character as a part of an attribute value in the following way: ......... <ConditionalStatement seqNumber="5" relationalOp="S<"/> ......... If I try to use the...
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
7
by: Diandian Zhang | last post by:
Does anyone have an idea, how to do it? Thanks in advance!
4
by: | last post by:
Hello NG! Within a xsl-stylesheet I have an element <xsl:text><!]></xsl:text> If I use that stylesheet to transform some xml-data (to html) with .... pOut = New System.IO.StringWriter
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
3
by: Steven.Xu | last post by:
hi everybody, i am useing some classes which in System.Xml to deal with xml document. what can i do if the document include "<" or ">"? Thanks.
1
by: ismailc | last post by:
Hi, I need help please. Update system to to new version & moved on to .Net2 But now my code that worked in my .Net1 xslt does not work. .Net1 fine: <xsl:stylesheet...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.