【C++】vector使用pair/tuple

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

v e c t o r 使用 p a i r 类型 \color{VIOLET}vector使用pair类型 vector使用pair类型

∙ \bullet 创建vector对象

vector<pair<int,int>>example;

∙ \bullet 插入pair<int,int>元素

example.emplace_back(1,2);
//或者
example.emplace_back(make_pair(1,2));

∙ \bullet 遍历vector数组

for(int i=0;i<example.size();i++)
{
	//依次输出每个pair对的第一个、第二个元素
	cout<<example[i].first<<" "<<example[i].second<<endl;
}

v e c t o r 使用 t u p l e 类型 \color{VIOLET}vector使用tuple类型 vector使用tuple类型

∙ \bullet 创建vector对象

vector<tuple<string,int,int>>example;

∙ \bullet 插入tuple<string,int,int>元素

example.emplace_back("aka",1,2);

∙ \bullet 遍历vector数组

for(auto ans:example)
{
	cout<<get<0>(ans)<<" "<<get<1>(ans)<<" "<<get<2>(ans)<<endl; 
}
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: c++