basic question about getting input

Mar 5, 2013 at 9:51pm
I can't understand why the code segment below isn't working properly. After I input a price (say 18.70), the program outputs "What is the name of this product?What is the score of this product?" as if it just ignores the getline(cin, c) command. Why does this happen? Thanks!



int a;
double b;
string c;

cout<<"What is the price of this product?";
cin>>b;

cout<<"What is the name of this product?";
getline(cin, c);

cout<<"What is the score of this product?";
cin>>a;
Mar 5, 2013 at 10:08pm
Why are you using getline(cin, c);

Just use another cin statement like this:

cin >> c;

Or maybe try changing the string type to char
Mar 5, 2013 at 10:23pm
I'm using getline because the input might have spaces in it (I might want to enter "Buzz lightyear doll" or something), so I want to pick up the entire string.
Topic archived. No new replies allowed.