Given a multimap M what\'s a neat way to create a vector of all values in M with a specific key.
multimap
vector
e.g given a multimap how c
Here's the way to do it STL style :
// The following define is needed for select2nd with DinkumWare STL under VC++ #define _HAS_TRADITIONAL_STL 1 #include #include #include #include #include #include #include #include using namespace std; void main() { typedef multimap MapType; MapType m; vector v; // Test data for(int i = 0; i < 10; ++i) { m.insert(make_pair("123", i * 2)); m.insert(make_pair("12", i)); } MapType::iterator i = m.lower_bound("123"); MapType::iterator j = m.upper_bound("123"); transform(i, j, back_inserter(v), select2nd()); copy(v.begin(), v.end(), ostream_iterator(cout, ",")); }