【C++标准库】通用工具

Pair

pair将两个value视为一个单元,struct pair定义在头文件<utility>中。

Tuple

tuple扩展了pair的概念,拥有任意数量的元素,位于<tuple>头文件中。

tuple<int, float, string> t1(41, 6.3, "nico");
cout << get<0>(t1) << endl; //41
cout << get<1>(t1) << endl; //6.3
cout << get<2>(t1) << endl; //nico
auto t2 = make_tuple(22, 44, "tom"); //使用make_tuple()创建tuple

猜你喜欢

转载自www.cnblogs.com/larry-xia/p/9273557.html