473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

getline(cin, string) Question

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: pv**@rose.edu
** Home e-mail: p_**********@cox.net
** Web Page: http://www.rose.edu/Faculty/pvan/index.htm
************************************************** ********************
Nov 16 '05 #1
1 4603
Peter van der Goes <p_**********@mars.cox.net> wrote:
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?


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

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
Nov 16 '05 #2

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

Similar topics

7
by: Sonoman | last post by:
I am trying to do this: cin >> temp; if (temp == "n"){ Then do something... } temp was declared as a string and the input I give at the prompt is n, but it skips the condition for the if...
5
by: Danny Anderson | last post by:
Hola- I didn't get any responses on a previous post, so I am trying to reword my problem and post compile-able code that exhibits the behavior I am describing. On the second iteration of the...
18
by: Amadeus W. M. | last post by:
I'm trying to read a whole file as a single string, using the getline() function, as in the example below. I can't tell what I'm doing wrong. Tried g++ 3.2, 3.4 and 4.0. Thanks! #include...
1
by: Jack | last post by:
Hi: Assume that the content of the file textfile.txt is: Have a good day. Hello world. I use the following code to access the file textfile.txt: #include <iostream>
1
by: m3zmeriz3d | last post by:
i typed a function to enter data into a file to be recalled later, now i have done something here and as soon as this function begins it skips the first 'zips' getline and makes it a blank space and...
1
by: l46kok | last post by:
Just wondering, for character of arrays, you can set the delimiter manually like cin.getline(character array, size, delimeter) But for the STL string, apparently, you have to use the following...
11
by: Key9 | last post by:
Hi all This is an simple app : read cin and print to cout I want it's action like "cat" with out arguement. #include <iostream> #include <string> using namespace std;
4
by: PulsarSL | last post by:
Hi I'm working on improving the "Simpletron" computer described in Deitel & Deitel's "C++ How to Program" 3rd edition. Check out http://www.lehigh.edu/~ejk0/smlspec.pas for a description if...
5
by: erictheone | last post by:
so here is my code. My getlines for the strings keyword and phrase at lines 44 and 79 respectively don't work. Please help!!! #include <cstdlib> #include <string> #include <iostream> #include...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.