getline() doesn't seem to work?

Joseph H. Buehler jhpb@sarto.gaithersburg.md.us
Fri Jan 30 05:40:00 GMT 1998


Adrian Miranda <ade@psg.com> writes:

> I am using egcs 1.0.1 on HP-UX 10.20.
> 
> I don't know if this is a bug in getline, or just a bug in my
> understanding of getline.  When I have the following program just
> reading from my terminal, I have to hit control-D twice before the
> loop exits.  It appears that the first time I hit control-D, getline
> does not even return, it's only when I hit CONTROL-D a second time
> that getline returns false, and the loop exits.
> 
> 
> #include <iostream.h>
> main() {
>     char word[100];
>     while(cin.getline(word, 100, '\n')) {
>         cout << "Got another line" << endl;
>     }
> }

Same thing happens on my linux machine.

Joe Buehler



More information about the Gcc mailing list