i got some problem with vector of vector. in my program, i have defined a dynamic memory for vector of vector and did the resize and push_back the elements.
vector<vector<double> > *planes = new vector<vector<double> >
planes->resize(s_list->size()); // size of another vector that i need to use
vector<int>::iterator s_no;
for(s_no=s_list->begin(), int i=0; s_no!=s_list->end(); s_no++, i++){){
//where i i the indices of planes
//some codes for computing length, width
planes->at(i).push_back(lenght);
planes->at(i).push_back(width);
}
it works and i got the print of all values what i added. then, i changed new vector defining part as follows
vector<vector<double> > *planes =
new vector<vector<double> >(s_list->size(),vector<double>(2,0.0))
and removed the resize part. then, when i got the print out of vector of vector, i got 0 values for all. could you please rectify this issue.
Use
atinstead ofpush_backpush_back() adds new items, therefore you end with with 4 items in each vector. You should use at() to modify the existing entries.
Better still is to use a
vector< pair<double,double> >, assuming you will always have two items.