
#include<iostream>
#include<set>
using namespace std;
#include<string>
//pair对组创建
void printSet(set<int>&s)
{
for (set<int>::const_iterator it = s.begin(); it != s.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
void test01()
{
pair<string, int>p("tom", 10);
cout << "姓名:" << p.first << " 年龄:" << p.second << endl;
//第二种
pair<string, int>p2 = make_pair("jerry", 30);
cout << "姓名:" << p2.first << " 年龄:" << p2.second << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
本文展示了如何在C++中使用pair来创建和初始化数据,并通过示例函数`test01()`演示了pair的两种创建方式。同时,代码中包含了一个打印set元素的辅助函数`printSet()`,强调了C++容器set的基本操作。
1076

被折叠的 条评论
为什么被折叠?



