###前提・実現したいこと
文字列のキーと構造体の値を持つstd::mapとキーを格納したstd::vectorがあり、std::mapのキーに対応する値の1つのメンバ変数をもとにキーを格納したstd::vectorをソートしたい。
###コード
#include <vector> #include <map> #include <string> #include <algorithm> using namespace std; struct Person { string name; unsigned int age; }; int main() { //値はすでに格納されているものとする map<string, Person> person_map; vector<string> person_key; //sortobjectの部分をどうするか? sort(person_key.begin(), person_key.end(), sortobject); //最も若い人物の名前を表示する cout << person_map[person_key[0]].name.c_str() << '(' << person_map[person_key[0]].age << ')' << endl; return 0; }
###補足情報(言語/FW/ツール等のバージョンなど)
Visual Studio Community 2017を使用。言語はC++。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。