Copy std::map into std::vector of pairs
问题 I'm trying to copy a map into a vector of pair, so I can then sort the vector by the second data member of the pairs. I have resolved this doing like this: void mappedWordsListSorter(){ for (auto itr = mappedWordsList.begin(); itr != mappedWordsList.end(); ++itr){ vectorWordsList.push_back(*itr); } sort(vectorWordsList.begin(), vectorWordsList.end(), [=](pair<string, int>& a, pair<string, int>& b){return a.second > b.second;}); } I need to find a way to do this without using a raw loop, using