fork download
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4. void report_error(string&s){ cout<<"error : parsing int failed : "<<s<<endl;}
  5. void do_smth(int x){ cout<<x<<endl;}
  6. int main(){
  7. istream& input=cin;
  8. string s;
  9. int x;
  10. while(input>>s){
  11. stringstream ss(s);
  12. ss>>x;
  13. if (!ss.eof()) {// не дошли при парсинге инта до конца строки
  14. //значит x отметаем
  15. report_error(s);
  16. continue;
  17. }
  18. do_smth(x);
  19. }
  20. }
Success #stdin #stdout 0s 15240KB
stdin
123e2 123 2 
stdout
error : parsing int failed : 123e2
123
2