Search This Blog

Sunday, November 15, 2009

C++, Vector of Vector for 2-D Array

vector > v;
//vector(), create an un-named vector with default constructor
v.push_back(vector()); //cannot push vector type safe! good.
cout << "size of v:"< v[0].push_back(10);
v[0].push_back(11);
cout << "size of v[0]:" << v[0].size() << endl;
cout << "v[0][0]:" << v[0][0] << endl; //10
cout << "v[0][1]:" << v[0][1] << endl; //11

//
vector > m(3, vector(5)); //3 vectors, each contains 5 vectors

No comments: