//vector容器中嵌套容器
#include<iostream>
using namespace std;
#include<vector>
int main()
{
//创建vector容器
vector<vector<int>> temp;
vector<int> temp1;
vector<int> temp2;
vector<int> temp3;
//向vector容器中写入数据
for (int i = 0; i < 5;i++)
{
temp1.push_back(i + 1);
temp2.push_back(i + 2);
temp3.push_back(i + 3);
}
//按尾插法添加数据,把vector放入vector须在完成数据存放后
temp.push_back(temp1);
temp.push_back(temp2);
temp.push_back(temp3);
//打印容器中的数据
for (vector<vector<int>>::iterator it = temp.begin(); it != temp.end(); it++)
{
for (vector<int>::iterator it1 = (*it).begin(); it1 != (*it).end(); it1++)
{
cout << *it1 << ' ';
}
cout << endl;
}
system("pause");
}
【C++学习纪录】vector容器——容器中嵌套容器
最新推荐文章于 2023-12-20 12:15:48 发布