getline(cin, string) Question

P

Peter van der Goes

Had this question from a student and confirmed the behavior in VC++ .NET
2003:
cout << "Please enter your name: ";
getline(cin,myName);
cin.ignore(100,'\n');

The only problem with this is I have to press "enter"
twice before the input is accepted. Is there a way to
eliminate the need for twice pressing "enter"?

I realize this has been around quite a while (research indicates since
VC5?), but is there a practical workaround that can be placed in the code?
If not, what are the alternatives?
Thanks!

--
**********************************************************************
** All opinions are mine alone.Do not attribute elsewhere!
**********************************************************************
** Peter van der Goes, Professor, Computers & Information Technology
** Rose State College
*********************** Contact ************************************
** Office e-mail: (e-mail address removed)
** Home e-mail: (e-mail address removed)
** Web Page: http://www.rose.edu/Faculty/pvan/index.htm
**********************************************************************
 
H

Hendrik Schober

Peter van der Goes said:
Had this question from a student and confirmed the behavior in VC++ .NET
2003:


I realize this has been around quite a while (research indicates since
VC5?), but is there a practical workaround that can be placed in the code?
If not, what are the alternatives?

What's that 'ignore()' call for? Remove it
and you won't need to hit enter twice.


Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top