How to Ingore the input of std::cin??

Y

yw

Hi,
When I use std::cin and std::cout to input some data, how can I ingore the
cin by using the Enter key?
For example:

string sname;
cout<<"Please input your name:"<<endl;
cin>>sname;

If I don't wan't to input anything, just press enter key to ingnore the cin
step, and jump the cin step when the cin requires to input something?

Thanks ,any help will be appreciate.
 
V

Victor Bazarov

yw said:
When I use std::cin and std::cout to input some data, how can I ingore the
cin by using the Enter key?

Not sure I understand.
For example:

string sname;
cout<<"Please input your name:"<<endl;
cin>>sname;

If I don't wan't to input anything, just press enter key to ingnore the
cin
step, and jump the cin step when the cin requires to input something?

If you just press the enter key, what happens? Does it still sit there
waiting or does the 'sname' come out empty?
 
D

David Harmon

On Sat, 5 Feb 2005 11:59:21 +0800 in comp.lang.c++, "yw"
string sname;
cout<<"Please input your name:"<<endl;
cin>>sname;

std::getline(cin, sname);
 
R

Ron Natalie

yw said:
Hi,
When I use std::cin and std::cout to input some data, how can I ingore the
cin by using the Enter key?
For example:

string sname;
cout<<"Please input your name:"<<endl;
cin>>sname;
Lookup basic_istream::ignore?
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top