C++中vector容器嵌套

#include
using namespace std;
#include

void test01()
{
	vector< vector > v;

	vectorv1;
	vectorv2;
	vectorv3;
	vectorv4;

	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 >::iterator it = v.begin(); it != v.end(); it++)
	{
		//it是v的各个指针地址,*it是v存放的数据,也就是子容器的各个指针地址,**it就是子容器存放的各个数据
		for (vector::iterator vit = (*it).begin(); vit != (*it).end(); vit++)
		{
			cout << (*vit) << " ";
		}
		cout << endl;
	}
}

int main() {
	test01();
}

你可能感兴趣的:(c++,c++,算法,开发语言)