std::pair

来源:互联网 发布:nginx mysql 安装 编辑:程序博客网 时间:2024/05/17 22:37

This class couples together a pair of values, which may be of different types (T1 and T2). The individual values can be accessed through its public members first and second.

示例:

#include <utility>      // std::pair, std::make_pair#include <string>       // std::string#include <iostream>     // std::coutint main () {  std::pair <std::string,int> planet, homeplanet;  planet = std::make_pair("Earth",6371);  homeplanet = planet;  std::cout << "Home planet: " << homeplanet.first << '\n';  std::cout << "Planet size: " << homeplanet.second << '\n';  return 0;}

Output:
Home planet: Earth
Planet size: 6371

#include <utility>      // std::pair#include <iostream>     // std::coutint main () {  std::pair<int,char> foo (10,'a');  std::pair<int,char> bar (90,'z');  foo.swap(bar);  std::cout << "foo contains: " << foo.first;  std::cout << " and " << foo.second << '\n';  return 0;}

foo contains: 90 and z

0 0
原创粉丝点击