C++ - Does Resetting Stringstream Not Reset The Get Position Or Clear Flags?
Answer : As @Someprogrammerdude suggests: simply move your istringstream inside your while loop (which you can change to a for loop to keep in in the loop as well): for (string in; cin >> in;) { istringstream word(in); int number; if (!(word >> number)) { cerr << "Failed to read int" << endl; return 1; } cout << in << ' ' << number << endl; } that way it's re-created each loop. While you're at it, move number in there too (unless you use it outside the loop, of course). If you look at the state of the stream, this should be a bit clearer. int main() { std::vector<std::string> words = { "10", "55", "65" }; std::istringstream word; for (const auto &in : words) { word.str(in); std::cout << "stream state:" << (word.rdstate() & std::ios::badbit ? "...