473,583 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.
Jul 23 '05 #1
3 1914
"yw" <pe******@hotma il.com> wrote...
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?
Jul 23 '05 #2
On Sat, 5 Feb 2005 11:59:21 +0800 in comp.lang.c++, "yw"
<pe******@hotma il.com> wrote,
string sname;
cout<<"Pleas e input your name:"<<endl;
cin>>sname;


std::getline(ci n, sname);

Jul 23 '05 #3
yw wrote:
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?
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1980
by: William Payne | last post by:
Hello, when I was writing a user-driven test program for a data structure I wrote, I encountered an annoying problem. The test program is laid out as a menu with several numbered options. The user selects one option by typing in its corresponding number (int). Depending on the choice he made, he may be asked to provide another integer (or no...
5
12234
by: Chris Mantoulidis | last post by:
Let's say I have this: std::string s1; std::cin >> s1; This will read s1 from cin until it finds a space (or a newline, whichever comes first). Okay this works. But when I want to continue reading it reads what's left over in the cin, and well that's logical.
3
7072
by: puzzlecracker | last post by:
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); I have seen it in faq - what does it do, exactly?
3
5297
by: moleskyca1 | last post by:
In C++ FAQ (15.5), I see this code: int i = 0; while (std::cin >x) { // RIGHT! (reliable) ++i; // Work with x ... } but I don't know how can while loop end? ostream &operator >>(...) return ostream &. how can that ever end the while loop? Is it because there is hidden operator to cast to int? I cannot figure out, please help?
8
3462
by: Johannes Meng | last post by:
Good day, I'm experimenting with unbuffered input at the moment. To get input I basically use cin.get(). My problem are control sequences preceeded by an ESC character (i.e. up, down, f-keys et cetera). They basically look like this: <ESC><EXCODE><CODE>, where EXCODE is a number describing the type of key pressed and CODE is the actual key....
3
14672
by: Ralf Goertz | last post by:
Hi, consider the following program #include <iostream> #include <fstream> using namespace std; int main(int argc, char *argv){
12
3301
by: pekka | last post by:
I'm trying to measure user input time with my Timer class object. It isn't as easy as I expected. When using std::cin between timer start and stop, I get zero elapsed time. For some unknown reason, the clock seems to stop ticking during execution of std::cin. Here's my code: #include <ctime> #include <iostream> #include <string>
7
5094
by: Sanyi | last post by:
What is cin's streambuffer's state and content after the following (using namespace std)? string((istreambuf_iterator<char>(cin)), istreambuf_iterator<char>()) ); I am trying to use this in a loop (to get a 'multiple cat'-like behavior) and the second time around it returns an empty string instead of waiting for more input. This makes me...
3
2881
by: Alex Snast | last post by:
hello guys I need to modify the std::cin delim char from the default ' ' and '\n' characters to ',' i know that i can edit the delim in the getline command however i'd like to know if there's something build in with me having to overload the std::cin operator thanks, Alex Snast.
0
7896
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7827
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8184
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8195
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5701
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3845
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.