fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <iterator>
  4.  
  5. template <class T,
  6. class OutputIt /* deduced */,
  7. class CharT /* deduced */>
  8. OutputIt copy_from_istream(std::basic_istream<CharT> & stream, OutputIt out) {
  9. return std::copy(
  10. std::istream_iterator<T, CharT>(stream),
  11. std::istream_iterator<T>(),
  12. out
  13. );
  14. }
  15.  
  16. int main() {
  17. std::vector<int> v;
  18.  
  19. // copy
  20. copy_from_istream<int>(std::cin, std::back_inserter(v));
  21.  
  22. // test
  23. for (int i : v)
  24. std::cout << i << ',';
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 3432KB
stdin
1 2 3 4 5
stdout
1,2,3,4,5,