fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. void input(vector<int>& number)
  8. {
  9. int num;
  10. int dec;
  11. do{
  12. cout << "Please enter the next number: ";
  13. if (cin >> num) {
  14. number.push_back(num);
  15. }
  16. else {
  17. std::string dummy;
  18. cin.clear();
  19. cin >> dummy;
  20. }
  21. cout << "Do you want to end? enter 0 to continue.";
  22. dec = -1;
  23. if (!(cin >> dec)) {
  24. std::string dummy;
  25. cin.clear();
  26. cin >> dummy;
  27. break;
  28. }
  29. } while (dec == 0);
  30.  
  31. for (int i = 0; i < number.size(); i++) {
  32. cout << number[i];
  33. }
  34. cout.flush();
  35. }
  36.  
  37. int main() {
  38. std::vector<int> vec;
  39. input(vec);
  40. return 0;
  41. }
Success #stdin #stdout 0s 3236KB
stdin
1
0
2
0
3
0
4
xyz
stdout
Please enter the next number: Do you want to end? enter 0 to continue.Please enter the next number: Do you want to end? enter 0 to continue.Please enter the next number: Do you want to end? enter 0 to continue.Please enter the next number: Do you want to end? enter 0 to continue.1234