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

Your map code seems fine. Maybe post more code, where s and v are declared. It seems like this wasn't copied and pasted, since there's a few program-busting spelling mistakes in it. You might want to fix those.

Right, thanks for the fast response. If there's nothing wrong with the map code, then I'll need to do some more digging, I can't post my entire program because it's too large and split over a number of files, so I'll try to find out what is causing the problem and if I can't fix it I'll post another fragment. Thanks again for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.