fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. vector<vector<int> > vec;
  5.  
  6. int main() {
  7. vec.resize(5); // Only the first dimension has the fixed size
  8. vec.at(2).push_back(2); // If I do vec[2].push_back(2), it will work
  9. vec.at(1).push_back(34);
  10. for (int i = 0; i < 5; ++i) {
  11. cout << vec[i].size() << endl; // output: 0
  12. for (int j = 0; j < vec[i].size(); ++j) {
  13. cout << vec[i][j] << endl;
  14. }
  15. }
  16. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
0
1
34
1
2
0
0