I’ve created a map of vectors that looks like this:
map<string, vector<char> > myMap;
string key = "myKey";
vector<char> myVector;
myMap[key] = myVector;
I want to be able to append ‘char’s’ to the vector in the map but I can’t figure out how to access said vector to append once the particular key/value(vector) has been created. Any suggestions? I’m iterating over char’s and might be adding a lot to the vector as I go so it would be nice to have a simple way to do it. Thanks.
I would like the vector in map to be appended as I go. I don’t need the original vector…I just need to return the map of key/vector’s that I’ve created (after apending) so that I can pass it to another function. What does the * in map* > do? Is that refrencing a pointer? (I haven’t gotten there in lecture yet) Also, do I need:
myMap[key]->push_back(‘s’);
or
myMap[key].push_back(‘s’);
??
To append:
Or use
myMap.find, but then you have to check whether you get anenditerator.operator[]returns a reference to thevector.But this modifies the
vectorstored in themap, not the original one, since you’ve stored a copy in themapwithmyMap[key] = myVector;. If that’s not what you want, you should rethink your design and maybe store (smart) pointers to vectors in your map.