Nested vector container C ++

Nested vector container C ++

#include <iostream>
#include <vector>
using namespace std;
class Test
{
public:
	Test() {};
	Test(int x):x(x) {};
	~Test() {};
	vector<int> x;//在类里使用动态数组作为成员变量

};
void test() {

	vector<Test2> my;
	
	Test2 t1;               
	for (int i = 0; i < 5; i++)
	{
		(t1.x).push_back(10 + i + i);
	}
	Test2 t2;
	for (int i = 0; i < 5; i++)
	{
		(t2.x).push_back(20 + i + i);
	}

	my.push_back(t1);
	my.push_back(t2);

	for (vector<Test2> ::iterator Vbegin = my.begin(); Vbegin!=my.end(); Vbegin++)
	{
		for (vector<int> ::iterator Ibegin = ((*Vbegin).x).begin(); Ibegin != ((*Vbegin).x).end(); Ibegin++)
		{
			cout << (*Ibegin) << ends;
		}
		cout << endl;
	}
}
void main() {
	test();
}

Renderings:
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_44567289/article/details/90631720