|
// Program: Vector of Vectors Demo
// Purpose: To demonstrate nested STL containers
// #include "stdafx.h" - include if you use pre compiled headers
#include <iostream>
#include <vector>
using namespace std;
typedef vector <int> VEC_INT;
int inp[2][2] = {{1, 1}, {2, 0}}; // Regular 2x2 array to place into the template
int main(int argc, char* argv[])
{
int i, j;
vector <VEC_INT> vecvec;
// if you want to do this in all one step it looks like this:
// vector <vector <int> > vecvec;
// Fill it in with the array
VEC_INT v0(inp[0], inp[0]+2); // passing two pointers for the range of values to be copied to the vector
VEC_INT v1(inp[1], inp[1]+2);
vecvec.push_back(v0);
vecvec.push_back(v1);
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
cout << vecvec[i][j] << " ";
}
cout << endl;
}
return 0;
}
// Output:
// 1 1
// 2 0
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.