fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <vector>
  4.  
  5.  
  6.  
  7. template <typename InnerType, typename Container>
  8. void fill_container(Container& cont)
  9. {
  10. std::copy(std::istream_iterator<InnerType>(std::cin),
  11. std::istream_iterator<InnerType>(),
  12. std::inserter(cont, cont.end()));
  13. }
  14.  
  15. template <typename InnerType, typename Container>
  16. void print_container(const Container& cont)
  17. {
  18. std::copy(std::begin(cont), std::end(cont),
  19. std::ostream_iterator<InnerType>(std::cout, " "));
  20. }
  21.  
  22.  
  23. int main(int argc, char const *argv[])
  24. {
  25. std::vector<int> vect;
  26.  
  27. fill_container<int>(vect);
  28. print_container<int>(vect);
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3476KB
stdin
1 2 3 
 5 6 8 
8 5 6 9 

end
stdout
1 2 3 5 6 8 8 5 6 9