fork download
  1. #include <iostream>
  2. #include <vector>
  3. int main()
  4. {
  5. std::vector<int> v;
  6.  
  7. int n;
  8. while( v.size() < 10 // while there are less than 10 values entered
  9. && (std::cin >> n) // and an integer can be read from the input
  10. && n != 0 ) // and the value entered isn't zero
  11. {
  12. v.push_back(n); // remember the value
  13. }
  14.  
  15. std::cout << "The values that were entered: ";
  16. for(auto n: v)
  17. std::cout << n << ' ';
  18. std::cout << '\n';
  19. }
  20.  
Success #stdin #stdout 0s 3032KB
stdin
1 2 3 4 0
stdout
The values that were entered: 1 2 3 4