Lets we have
std::vector <std::vector <int>> myVec;
myVec.resize(100);
myVec[0].push_back(1);
myVec[0].push_back(2);
When I break the program with a breakpoint, I see that both size and capacity of each myVec[] is zero. Additionally, when I try to access myVec[0][0], it gives access violation error. How this could be?
P.S.: I am using VS 10
Your code snippet seems to be perfectly correct. If you have problems with access violation, your problem is somewhere else.
Here’s an example:
output:
If someone is confused by using resize for filling empty vector, check this
Hope this helps 😉