Bernard Asked:2020-03-27 03:48:02 +0000 UTC2020-03-27 03:48:02 +0000 UTC 2020-03-27 03:48:02 +0000 UTC 如何按map中的值对向量进行排序 772 我有一个矢量图 std::vector <std::string> v; // ["a", "b", "c"] 和一个映射,其中键是向量的元素,值只是一个整数 std::map <std::string, int> m; // {"a"=1, "b"=2, "c"=1} 如何按 in 中的数值对向量的元素进行排序map? c++ 1 个回答 Voted Best Answer Harry 2020-03-27T03:55:29Z2020-03-27T03:55:29Z sort(v.begin(),v.end(), [&m](const string& a, const string& b){return m[a] < m[b]; }); 像这样的东西......好吧,或者如果它m是全局的,那么&m在方括号中没有它。
像这样的东西......好吧,或者如果它
m是全局的,那么&m在方括号中没有它。