fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template<class T, class CharT, class CharTraits>
  5. std::vector<T> read(std::basic_istream<CharT, CharTraits> &in) {
  6. std::vector<T> ret;
  7. while(in.good()) {
  8. T x;
  9. in >> x;
  10. if(in.good()) ret.push_back(x);
  11. }
  12. return ret;
  13. }
  14.  
  15. int main() {
  16. auto v = read<int>(std::cin);
  17.  
  18. for(const auto &x : v) std::cout << x << " ";
  19. std::cout << std::endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 2988KB
stdin
1 2 3 9 9 9 
5 6 434 54 4
4
stdout
1 2 3 9 9 9 5 6 434 54 4 4