c++ - How do I know when one is done entering cin with \n? (loop) -
from australian voting problem:
a bot keep putting information , can reach 1000 lines. example of he'll enter:
"1 2 3 2 1 3 2 3 1 1 2 3 3 1 2 "
how know when has finished entering information? there \n @ end , that's guess on go. cin doesn't seem detect \n, getchar() apparently does. \n after first line of course, , getting work has become rather difficult. how accomplish this?
std::string line; while( std::getline(std::cin,line) && !line.empty() ) { std::istringstream iss(line); int i1, i2, i3; iss >> i1 >> i2 >> i3 if( !is ) throw "dammit!" process_numbers(i1,i2,i3); } if( !std::cin.good() && !std::cin.eof() ) throw "dammit!";
Comments
Post a Comment