Search code examples
c++vectoroverloadingoperator-keyword

Overload c++ operator >> so i can read a vector (vector <int> vector;)


i want to know how i can overload the >> operator so i can read a vector or a matrix just doing cin >> vector vector().

Thanks!


Solution

  •   template <typename T>
      std::istream& operator>>(std::istream& is, std::vector<T>& v) {
        std::copy(std::istream_iterator<T>(is), std::istream_iterator<T>(),
                  std::back_inserter(v));
        return is;
      }