If I have a map of vectors, map> myMap; I can put stuff, given a key, into myMap like so: myMap[key].push_back(someString); Is there a way that I can see how many elements are in the vector associated with a given key? such as myMap[key].second.size; ? and then, to print the vector elements out, could I loop through the mapped vector and do cout << myMap[key].second[i]; where 'i' is the position in the vector?
Still Need Help?
Join the QuestionCove community and study together with friends!
Sign Up
OpenStudy (rsmith6559):
Wouldn't: myMap[ key ].size() do it? I don't see where "second" in your question comes from. The vector is the result of myMap[ key ], so I would think that myMap[ key ][ i ] would refer to an element of the vector.
OpenStudy (anonymous):
ooookay, that makes more sense. Okay, then.
So, if I am iterating through my map like so:
for(auto it = myMap.begin(); it != myMap.end(); ++it) and then I want to check the size of the vector where the iterator is currently pointing. would that be it -> second.size();?
OpenStudy (rsmith6559):
You can always write a little test program on the side to check these things out. I thought you were going more for:
for( int i = 0; i < myMap[ key ].size(); i++ )
std::cout << myMap[ key ][ i ] << std::endl;
OpenStudy (anonymous):
yeah, I'll have to test a couple different things out ^_^; Thanks for helping me! (even though my question was kinda silly...)