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. 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?
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);
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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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.
|
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?
|
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?
|
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....
| |
by: Ralf Goertz |
last post by:
Hi,
consider the following program
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv){
|
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>
|
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...
|
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.
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |