Hello,
I want to get input from an amount of integers,but after it get input to a string with getline(cin,stringname);
But the enter that the user gives when he input numbers to the ints,gets into the string and it doesn't get any input(sentence) to the string,only the "enter" key.
how can I solve that?
Thanks.
views:
233answers:
4
A:
Code:
cin>>track.day; //Int
cin>>track.seriesday; //Int
getline(cin,track.comment); //String
The string fill itself with the "enter" key and "skips" getting the string from the user,because of the enters pressed when the program requested input to the int.
so how can i clear the cin(cin.clear() don't work) so the string won't fill itself with "enter" key?
A:
Can you please paste the code where you read the integers? Also, what compiler are you using, and on which platform?
dguaraglia
2008-10-02 19:22:29
+1
A:
I think that your cin of the ints is not reading the new line before the sentence. cin skips leading whitespace and stops reading a number when it encounters a non-digit, including whitespace.
So:
std::cin >> num1;
std::cin >> num2;
std::cin.ignore(INT_MAX, '\n'); // ignore the new line which follows num2
std::getline(std::cin, sentence);
might work for you
Evan Teran
2008-10-02 19:22:49
Yes it works thank you very much!
2008-10-02 19:26:25