Hello All,
I am experiencing a problem with the STL map class (or rather the map class is experiencing a problem with me). I am trying to store a number of 2-dimensional vectors of type int, whose corresponding keys are strings. The problem arises when I try to index a 2-d vector. I can illustrate this with a short program fragment...
map<string, vector<vector<int> > > m;
map<string, vector<vector<int> > >::iterator p;
m.insert(make_pair(s, v)); // where s and v are a previously declared and initialized string and a previously declared and initialized 2 by 2 integer 2-d vector
for (p=m.begin(); p!=m.end(); p++){
// prints first and second element of first row...
cout << (p->second)[0][0] << " " << (p->second)[0][1]<< endl;
// expecting first and second element of second row...
cout << (p->second)[1][0] << " " << (p->second)[1][1]<< endl;
// ... but get nonsense
}
i.e. the first row prints fine but the second prints nonsense. The problem is the same for vectors of larger dimensions; the first row prints fine, all following rows print nonsense.
any help would be gratefully appreciated
Thanks