Thread overview
Problem with input, no output
Apr 15, 2004
David Harmon
Apr 15, 2004
David Harmon
Apr 15, 2004
Pablo Aguilar
Apr 15, 2004
David Harmon
April 15, 2004
Using Digital Mars Compiler Version 8.38n and stlport.  Win98SE.
Compile and run, enter some numbers, press ctrl-Z for EOF.
The output "Answer: " etc. never appears.  Uncomment the
indicated line, and all works as I expect.
Am I doing something dumb?

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
    typedef double T;
    vector<T> scores;
    cout << "Enter scores, EOF to end: ";
    copy(istream_iterator<T>(cin), istream_iterator<T>(),
            back_inserter(scores));
    // cout << "\nUncomment this line, problem goes away.\n";
    cout << "Answer: " << scores.size()  << '\n';
}

April 15, 2004
On Wed, 14 Apr 2004 18:33:08 -0700 in c++,
David Harmon <<source@netcom.com>> wrote:
>Using Digital Mars Compiler Version 8.38n and stlport.  Win98SE.

Sorry, "Digital Mars Compiler Version 8.38n" is the string it displays when run dmc with no arguments.  But it was downloaded as dm840c.zip so I guess I have got version 8.40.

April 15, 2004
try with an std::flush at the end:

cout << "Answer: " << scores.size()  << '\n' << flush;

> Using Digital Mars Compiler Version 8.38n and stlport.  Win98SE.
> Compile and run, enter some numbers, press ctrl-Z for EOF.
> The output "Answer: " etc. never appears.  Uncomment the
> indicated line, and all works as I expect.
> Am I doing something dumb?
>
> #include <iostream>
> #include <vector>
> #include <iterator>
> #include <algorithm>
> using namespace std;
> int main()
> {
>     typedef double T;
>     vector<T> scores;
>     cout << "Enter scores, EOF to end: ";
>     copy(istream_iterator<T>(cin), istream_iterator<T>(),
>             back_inserter(scores));
>     // cout << "\nUncomment this line, problem goes away.\n";
>     cout << "Answer: " << scores.size()  << '\n';
> }



April 15, 2004
On Thu, 15 Apr 2004 12:19:36 -0700 in c++,
"Pablo Aguilar" <paguilarg@hotmail.com> wrote:

>try with an std::flush at the end:
>
>cout << "Answer: " << scores.size()  << '\n' << flush;

OK, I have now tried that.  Same result.

Of course, the stream should normally be flushed at the end of execution automatically.  What was it that you expected that experiment to reveal?

The problem apparently has to do with the cout<<'\n' immediately after input EOF before outputting anything else.  That is what makes all the difference in my experiments now, but I see no reason why it should make such a difference.