Advertisement
fenixD3

input reading template

May 16th, 2023
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. template <template <typename> class TCont, typename TType>
  2. TCont<TType> fill_from(int count, std::istream& from)
  3. {
  4.     TCont<TType> seq;
  5.     seq.reserve(count);
  6.  
  7.     std::copy(
  8.         std::istream_iterator<TType>(from),
  9.         std::istream_iterator<TType>(),
  10.         std::inserter(seq, seq.end()));
  11.  
  12.     return seq;
  13. }
  14.  
  15. int main()
  16. {
  17.     int n;
  18.     std::cin >> n;
  19.  
  20.     std::vector<int> list_form = fill_from<std::vector, int>(n, std::cin);
  21. }
  22.  
  23. /*
  24. * Input:
  25. * 4
  26. * 1 2 3 4
  27. *
  28. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement