Lets say i have vector of vectors
vector< vector<int> > bigTable;
vector<int> data;
data.resize(2);
fingertable.resize(5,data);
How do i insert a vector in?
vector<int> newData;
newData.resize(2);
newData.push_back(123);
newData.push_back(456);
When i do the following, the data in the bigTable vector is still 0.
bigTable.push_back(newData);
cout << bigTable[0][0]; // this will produce an output of 0
I think you misunderstand what resize
does (perhaps you're thinking of reserve
?). After your second code snippet, newData
will contain 4 elements: 0
, 0
, 123
, 456
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.