功能描述
成对出现的数据,利用队组可以反回两个数据。
函数原型
pair<type,type>p(v1,v2);
pair<type,type>p = make_pair(v1,v2);
代码示例
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
void print(const set<int>& s)
{
for(set<int>::const_iterator it = s.begin(); it != s.end(); it++)
{
cout<< *it <<" ";
}
cout << endl;
}
void test()
{
pair<string,int>p("Tom",20);
cout << p.first << p.second << endl;
pair<string,int>p1 = make_pair("Jerry",20);
cout << p1.first << p1.second << endl;
}
int main()
{
test();
return 0;
}
结果输出