Re: (no subject)
Re: (no subject)
- Subject: Re: (no subject)
- From: Chris Gehlker <email@hidden>
- Date: Tue, 28 Aug 2001 21:08:09 -0700
On 8/28/01 8:04 PM, "Tony Cate" <email@hidden> wrote:
>
I know this belongs on the project builder list, but I don't happen
>
to know the address and I need a quick answer.
>
>
When trying to run a c++ app with the cin object, using the PB IDE,
>
output is held up until all the input has occurred. Example:
>
#include <iostream>
>
>
int main (int argc, const char * argv[])
>
{
>
float x;
>
cout << "Hello, World!";
>
cin >> x;
>
>
>
return 0;
>
}
>
>
The text "Hello World" will only print once I've input 'x'. If I had
>
6 cin's, I'd have to put then all in before the output would happen.
>
>
1 Why?
Because that's how it's supposed to work. The Wintel IDE is non-standard.
(Well that's a little strong. The standard doesn't forbid a flush. Lets just
say that C++ isn't supposed to make assumptions about what devices are
attached to standard input and standard output.)
>
2 How do I get around it? (I'm in a c++ class and this is the IDE I'm
>
using - everyone else is on wintel stuff.)
Use std::endl or std::flush, depending on whether or not you want a carriage
return. That is:
cout << "Hello World" << endl; // Is better form and works everywhere.
--
C++: The power, elegance and simplicity of a hand grenade.