やったこと
map を使ってみます。
確認環境
$ g++ --version
g++ (Homebrew GCC 9.2.0) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
調査
test.cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, int> m;
m.insert(make_pair("key1", 1));
m.insert(make_pair("key2", 5));
m.insert(make_pair("key3", 9));
printf("%d\n", m.at("key2"));
}
出力結果
5