Reputation: 33
For the following code, vv[1].size()
will return an output of 4. I was wondering where this number came from.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<vector<int>> vv;
vector<int> v1(3,5);
vector<int> v2(4,7);
vv.push_back(v1);
vv.push_back(v2);
cout << vv.size() << endl << vv[1].size() << endl;
}
Upvotes: 1
Views: 278
Reputation: 51
This is because vector<int> v2(4,7);
creates a vector of size 4 whose values are all 7. You most likely meant to write vector<int> v2 {4,7};
which creates a vector with 2 elements of 4 and 7.
Upvotes: 2