save a map in a vector that contains maps

Aug 25, 2012 at 6:27pm
Hey all,

I want to save a map in a vector that contains maps :
vector<map<string,unsigned int>>

code:
vector<map<string,unsigned int>> map_vec;
vector<map<string,unsigned int>>::iterator mapind; // iterator for vector
map<string,unsigned int> mapst;

mapind=map_vec.begin();
.
.
.
*mapind=mapst; // why that is wrong ?? how to correct it ??

Thank you
Aug 25, 2012 at 6:44pm
If the vector is empty you may not assign to it elements such a way. Use push_back method instead.
Last edited on Aug 25, 2012 at 7:05pm
Aug 25, 2012 at 7:03pm
Iterators are just temporary objects that hold a piece of their associated STL container. In this case you want to do:

map_vec.push_back(mapst);

instead of your *mapind=mapst;

If you need further help with this just ask! I've been making maps of maps of maps of vectors recently so I'm pretty much wired on the subject

Regards,
Anthony
Aug 25, 2012 at 7:06pm
thank u
Topic archived. No new replies allowed.