[Recommended] Simply do this : Ref. Range-based for loop
#include <iostream>
#include <vector>
int main() {
int N;
std::cin >> N;
std::vector<std::vector<int>> arr(N, std::vector<int>(2));
for (auto &&row : arr)
for (auto &&ele : row)
std::cin >> i;
}
The problem with your code is, you haven't told compiler how many elements are there in the vector.
Corrected code :
// ...
int main() {
int N;
cin >> N;
vector<vector<int>> arr(N);
for (int i = 0; i < N; i++) {
// ...
Another way to fix your code :
Add
arr.push_back(vector<int>());
just before inner loop :
for (int j = 0; j < 2; j++) {
One more way :
Add
arr.resize(N); // https://en.cppreference.com/w/cpp/container/vector/resize
just before outer loop :
for (int i = 0; i < N; i++) {
Bonus Tip :
If your data is limited to two columns only then you may consider using std::pair instead :
#include <iostream>
#include <utility>
#include <vector>
int main() {
int N;
std::cin >> N;
std::vector<std::pair<int, int>> arr(N);
for (auto &&i : arr)
std::cin >> i.first >> i.second;
}