c++ - Accessing a dynamic vector of vector -


here code:

std::vector< std::vector<int> > v;  v.push_back(std::vector<int>(2)); v[0].push_back(10);  std::cout<<(v[0])[0]; 

but prints "0" instead of 10.

i trying make dynamic vector holds vector fixed size.

can me visualize what's happening?

the code buggy:

std::vector<int>(2) 

makes vector of size 2 initialized deault constructed int (which zero), pushing 10 makes vector of size 3 w/ 10 @ end (index 2).


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -