Topic: std::getline prob


Author: "Syver Enstad" <syver.enstad@sensewave.com>
Date: 2000/10/09
Raw View
> The bug itself doesn't really bother me, since I rarely use console
output.
> I just wanted to make sure I hadn't missunderstood the stream library
> functions, which I've not used before.

It really is a bug, and the fixes work fine provided you link statically to
the std c++ library.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Dennis Yelle <dennis51@jps.net>
Date: 2000/09/25
Raw View
Gary Leighton wrote:
>
> In the example below, getline doesn't work as I expected. It requests input,
> which I complete with the return or enter key, and then requests some more
> keyboard input before finally outputting the first string only?
>
> This is an example from Stroustrups' C++ programming language book. It says
> that the program should simply accept your name and print it. Have I done
> something stupid here, or is this a problem with Visual C++ v6?
>
> #include <string>
> #include <iostream>
>
> using namespace std;
>
> int main(void) {
>
>  string str;
>
>  cout << "Please enter your name\n";
>  getline(cin,str);
>  cout << "Hello, " << str << "!\n";
>
>  return(0);
> }

It looks OK to me, and
gcc version 2.95.2 19991024 (release)
accepts it with no complaints even with
the options -Wall -ansi -pedantic

And it runs properly for me.

Did you compile EXACTLY the same source that
you posted?

Dennis Yelle
--
I am a computer programmer and I am looking for a job.
There is a link to my resume here:
http://table.jps.net/~vert/

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Ron Natalie <ron@sensor.com>
Date: 2000/09/26
Raw View

Gary Leighton wrote:
>
> int main(void) {
>
>  string str;
>
>  cout << "Please enter your name\n";
>  getline(cin,str);

Things are fine up to here.  cin and cout are tied together, so when you do the
getline, the text in the cout is flushed out.

>  cout << "Hello, " << str << "!\n";
>

Here I suspect is the heart of your problem.  This buffer will not be flushed until
the program exits.  I suspect that second enter you have to hit is an artifact VC++
console apps that have a "hit any key" at the end of them before they exit.

Try :

 cout << "Hello, " << str << "!\n" << flush;
(or)
 cout << "Hello, " << str << "!" << endl;

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Gary Leighton" <gary@leightong.freeserve.co.uk>
Date: 2000/09/26
Raw View
Ron,

John Hickin replied to me directly, to say that there is a fix at
http://www.dinkumware.com/vc_fixes.html
It seems this is a Microsoft VC5/6 bug effectively, but I haven't tried the
fix yet.

As for the flush / endl options, I still have to hit Enter or Return twice
before I get an output string, but flush combines both lines of output into
the output string (endl makes no difference).

The bug itself doesn't really bother me, since I rarely use console output.
I just wanted to make sure I hadn't missunderstood the stream library
functions, which I've not used before.

Cheers,

Gary

Ron Natalie <ron@sensor.com> wrote in message
news:39CF9924.2BCD9314@sensor.com...
>
>
> Gary Leighton wrote:
> >
> > int main(void) {
> >
> >  string str;
> >
> >  cout << "Please enter your name\n";
> >  getline(cin,str);
>
> Things are fine up to here.  cin and cout are tied together, so when you
do the
> getline, the text in the cout is flushed out.
>
> >  cout << "Hello, " << str << "!\n";
> >
>
> Here I suspect is the heart of your problem.  This buffer will not be
flushed until
> the program exits.  I suspect that second enter you have to hit is an
artifact VC++
> console apps that have a "hit any key" at the end of them before they
exit.
>
> Try :
>
> cout << "Hello, " << str << "!\n" << flush;
> (or)
> cout << "Hello, " << str << "!" << endl;
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]
>


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Renato Mancuso" <mancuso@ebi.ac.uk>
Date: 2000/09/27
Raw View
hi gary,

it is a known bug. The Dinkumware web site contains a list of fixes you can
apply to correct this and a few more bugs:

http://www.dinkumware.com/vc_fixes.html

regards

Renato Mancuso



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Gary Leighton" <gary@leightong.freeserve.co.uk>
Date: 2000/09/25
Raw View
In the example below, getline doesn't work as I expected. It requests input,
which I complete with the return or enter key, and then requests some more
keyboard input before finally outputting the first string only?

This is an example from Stroustrups' C++ programming language book. It says
that the program should simply accept your name and print it. Have I done
something stupid here, or is this a problem with Visual C++ v6?

#include <string>
#include <iostream>

using namespace std;

int main(void) {

 string str;

 cout << "Please enter your name\n";
 getline(cin,str);
 cout << "Hello, " << str << "!\n";

 return(0);
}


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]