C++STL——vector容器实现二维数组的输出
#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;void test01(){vector<vector<int>> v;vector<int> v1;v...
·
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
void test01()
{
vector<vector<int>> v;
vector<int> v1;
vector<int> v2;
vector<int> v3;
vector<int> v4;
for (int i = 0; i < 4; i++)
{
v1.push_back(i + 1);
v2.push_back(i + 2);
v3.push_back(i + 3);
v4.push_back(i + 4);
}
v.push_back(v1);
v.push_back(v2);
v.push_back(v3);
v.push_back(v4);
for (vector<vector<int>>::iterator it = v.begin(); it < v.end(); it++)
{
for (vector<int>::iterator vit = (*it).begin(); vit < (*it).end(); vit++)
{
cout << *vit << " ";
}
cout << endl;
}
}
int main()
{
test01();
return 0;
}
更多推荐
已为社区贡献1条内容
所有评论(0)