Click here to Skip to main content
15,892,737 members
Articles / Programming Languages / C++

Practical Guide to STL

Rate me:
Please Sign up or sign in to vote.
4.41/5 (65 votes)
12 Apr 200412 min read 493.6K   2.2K   117  
An article on practical learning of STL in the MS development environment.
// 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
I shuffle tiny static charges on intricate wafers of silicon all day.

Comments and Discussions