could you explain me when the reading of an int in C++ is terminated ? Is it terminated with withespace just as when we read into a string type object ?
Asked
Active
Viewed 61 times
-3
-
Could you enhance this question with a sample showing your particular observations, and what didn't work for you please? – πάντα ῥεῖ Sep 26 '14 at 17:19
-
See also: http://stackoverflow.com/questions/2075898/good-input-validation-loop-using-cin-c – Ming-Tang Sep 26 '14 at 17:22
1 Answers
0
If you have input line as space separated list like say 2 43 56, you need to read this as three integers as:
std::cin >> a >> b >> c;
where
int a, b, c;
Otherwise you need use cin.getline as in:
std::string name;
std::getline(std::cin, name);
and then parse, as required

Dr. Debasish Jana
- 6,980
- 4
- 30
- 69