c++ - Get only the first value from std::cin -
when reading input std::cin
want allow single numeric entry. given code
float n = 0; std::cin >> n;
how identify case user input 1 2 3
?
use getline
, istringstream
, run while
loop count number of integers entered:
string line; getline(cin, line); int x, cnt = 0; istringstream iss(line); while(iss >> x){ cnt++; }
cnt
3
1 2 3
.
Comments
Post a Comment