template <class T1, class T2> struct pair
#include <utility> using namespace std; pair <T1, T2> 変数名; pair <int, string> x; pair <int, string> x = make_pair(2, "abc"); pair <int, string> x({2, "abc"}); pair <int, string> x{2, "abc"}; pair <int, string> x = {2, "abc"};
= == != < <= > >=
#include <iostream> #include <map> using namespace std; int main() { map<string, int> m; // キーが string,値が int m.insert({"suzuki", 40}); m.insert(make_pair("yamada", 70)); cout << "m の要素数: " << m.size() << endl; for (auto x : m) cout << " (" << x.first << ", " << x.second << ")"; cout << endl; return 0; }
m の要素数: 2 (suzuki, 40) (yamada, 70)
菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |