Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

getline(cin, inputline);

–2 votes
asked Dec 25, 2017 by Jonjiissmiling c (160 points)
edited Dec 25, 2017 by Jonjiissmiling c
string name12;
    string city12;
    //Can use function getline to read the entire line. getline(cin, inputLine);
    cout << "Enter a name...first and last if you want: ";
    getline(cin, name12);
    cout << "Same deal with city: ";
    getline(cin, city12);
    cout << endl;
    cout << "So you said your name is: " << name12 << "And you live in " << city12;
    cout << " city." << endl << endl;

For whatever the reason, the program is skipping over the first cin. It displays the cout message:

Enter a name...first and last if you want: Same deal with city: (then it allows me to enter in for the city).

Then the cout message displays: So you said your name is: And you live in (and then what I entered) city.

??? Why is it skipping over the first getline(cint, inputline) for the name12 variable???;

1 Answer

0 votes
answered Dec 25, 2017 by anonymous
I just tried your code snippet and it seems to working as expected.
its reading name12 and city12 both.

https://onlinegdb.com/Hy6BzZ0fM
commented Dec 26, 2017 by Jonjiissmiling c (160 points)
Thanks. I realized what I did. This is just part of the program and there was previous cins that caused a skip I guess once it got to the 1st getline.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...