Re: <Help> Simple Pause Needed.
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 10/02/03
- Next message: Dave Vandervies: "Default arguments and prototypes"
- Previous message: Peter van Merkerk: "Re: Deleting Pointers from STL Vector"
- In reply to: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Next in thread: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Reply: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 02 Oct 2003 20:02:44 GMT
"Jonathan Mcdougall" <jonathanmcdougall@DELyahoo.ca> wrote in message
news:k5%eb.5830$yV2.104971@weber.videotron.net...
> > > I prefer using std::endl since it is clearer than a bunch of \n.
> > > It is also supposed to flush the buffer, but flushing the buffer
> > > does not necessrily mean that the data is written.
> >
> > Again, Eh?
>
> I prefer using std::endl since it is clearer than a bunch of \n.
I disagree. Any C++ programmer will know what '\n' means.
As readily as what e.g. 'int' means. I suppose it can
vary among people, but I find '\n' simpler reading.
> What's more, since std::cout is buffered, std::end flushes it.
Yes, I know. That's 'std::endl' :-)
> That
> does not mean the output will automatically get on the stdout though,
Where did you hear that? What do you think 'flush' means,
in the context of an output stream?
> since operating systems usually provide some buffering themselves
> (this applies to all streams).
Now you're outside the language. Nothing to do with
flushing a stream. And your generalization 'all streams'
is incorrect.
>To make sure the data gets written,
> you should use implementation-specific functions which deal with
> the operating system's buffer.
I vehemently disagree. If this were the case, C++ would
fail in its role as a platform independent language.
> But usually, flushing the buffer is enough.
"Usually", flushing a buffer is not necessary at all.
>Note that std::cout
> flushes the buffer when it is destroyed
During 'cout's destruction, it (the stream) is flushed.
>(ie at the end of the
> program), but you may have no time to see the output
Huh?
So you're saying that if I run:
#include <iostream>
int main()
{
std::cout << "Hello world\n";
return 0;
}
.. that the output might disappear immediatly after
appearing on the output device to which 'cout' is
attached? I don't think so. An IDE might interfere
with a 'screen' output, but that's outside the language.
>(in case
> of outputting to stdout when there is a screen on your system)
Absolutely not true.
> so make sure you flush the buffer yourself when you are
> finished writing.
Unnecessary, unless you require that the output appear
*immediately* after inserting data into the stream.
And it's not even necessary if a 'cout' insertion
is followed by a 'cin' extraction, since by defintion,
a 'cin' extraction will first cause 'cout' to be flushed
if necessary (look up 'tie()').
>
> Finally, '\n' may flush the buffer or not,
'\n' is not an operation. It's a value, that's all.
It cannot 'do' anything. A function might behave
in a particular way upon encountering it, this
behavior perhaps causing a flush.
>this is not defined
> (just as it may flush it with any character).
>
> Interesting note that I found in my researches, \n is
> translated into its equivalent depending on the platform.
That is common knowledge. It's a feature of a 'text mode'
stream, well documented.
> For example, when writing to a text file, Windows needs a
> \r\n and Mac gets a \r.
I know this.
No offense, but I think you're suffering from a few
misconceptions.
-Mike
- Next message: Dave Vandervies: "Default arguments and prototypes"
- Previous message: Peter van Merkerk: "Re: Deleting Pointers from STL Vector"
- In reply to: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Next in thread: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Reply: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|