0
vector <int> v[6];
     for(int i=0; i<v.size(); i++){
        cin>>v[i];
     }

I tried to change operator but it's not working.

CinCout
  • 9,486
  • 12
  • 49
  • 67
  • `vector v[6]` defines `v` as an array of `vector` but since there is no overloaded `operator>>` for `vector` we get the mentioned error. – Jason Dec 16 '22 at 06:20
  • In modern C++ its better to use "range for" instead of C-style for when iterating over containers (and in some other cases). So, use `for (int& i : v) { cin >> i; }` and in your case you will see compiler complaining right away that it can't asssign `std::vector&` to `int&`. – sklott Dec 16 '22 at 06:22
  • `[]` is used to declare arrays, you are trying to declare a vector with a given size. So you want to pass that size to the appropriate vector constructor. Use `()` for that `vector v(6);` – john Dec 16 '22 at 07:01

2 Answers2

0

You actually declared a 2-d structure by using both vector and [] together.

Either use vector<int> v(6) or int v[6] for a 1-d data structure.

CinCout
  • 9,486
  • 12
  • 49
  • 67
0

vector <int> v[6] defines v as an array of vector<int> thus v[i] gives us a vector<int> but since there is no overloaded operator>> for vector<int> we get the mentioned error.

Jason
  • 36,170
  • 5
  • 26
  • 60