c++ - How do I print out elements in a multimap ONLY n times -
my multimap has int key , string value. key number of times word has occurred , value word itself. figured if loop through multimap iterator @ rbegin , rend, can loop through ten times rather until reaches end find top ten words. idea how this?
sure! here's 1 option:
unsigned numtimes = 0; (auto itr = mymultimap.rbegin(); itr != mymultimap.rend() && numtimes < kmaxtimes; ++itr, ++numtimes) { /* itr */ }
Comments
Post a Comment