Copy std::map into std::vector of pairs

后端 未结 3 1392
时光取名叫无心
时光取名叫无心 2021-01-17 08:34

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:

3条回答
  •  广开言路
    2021-01-17 08:51

    It's worth noting that if you are creating a vector for this purpose, you may use the vector's constructor directly:

    std::vector> vectorWordsList( mappedWordsList.begin(), mappedWordsList.end() );
    

    In C++17, you may also omit the vector's template arguments to have the compiler deduce them:

    std::vector vectorWordsList( mappedWordsList.begin(), mappedWordsList.end() );
    

提交回复
热议问题