fork download
  1. #include <iostream>
  2.  
  3. std::istream& f(std::istream &in) {
  4. std::string temp = "";
  5. while(true) {
  6. while (in >> temp) {
  7. if (temp == "-1") {
  8. break;
  9. }
  10. std::cout << temp << std::endl;
  11. }
  12. if (in.eof()|| temp == "-1") break;
  13. if (!in) {
  14. std::cout << "Invalid input" << std::endl;
  15. in.clear();
  16. in.ignore(10000,32);
  17. }
  18. }
  19. in.seekg(0, std::ios::beg);
  20. return in;
  21. }
  22.  
  23. int main(){
  24. std::cout << "Please input some integers and end with ^Z or -1" << std::endl;
  25. f(std::cin);
  26. return 0;
  27. }
Success #stdin #stdout 0s 15240KB
stdin
13112132138121321515181
52415313
1.232863
-168135.151
-1
stdout
Please input some integers and end with ^Z or -1
13112132138121321515181
52415313
1.232863
-168135.151