|
A Crash Course in the C++ Standard Template Library Thursday, August 28, 2003
By Yarin TopCoder Member
Introduction This course tries to quickly teach how to use the Standard Template Library for the most common tasks without having to rely on other sources. It tells very little how things work, but instead gives several code snippets from which it should be possible to figure out how to use some parts of the STL. Since it's a crash course, a lot of things are left out and some things are simplified so much they're almost lies...
The STL is a collection of containers and simple algorithms. A container is something that holds several elements of the same type. The containers described in this course are vector, set and map, but the STL have several more containers. The STL header files required in this course are vector, set, map and algorithm. I also use iostream and string (the latter is not part of the STL, even though it in many ways have the same functionality). All classes are declared in the namespace std, so having the following lines at the beginning of your code is a good idea:
#include #include #include #include #include #include
using namespace std;
vector
A vector corresponds to a 1-dimensional array in C. A vector is declared like this:
vector a; // Declare a vector of integers vector b; // Declare a vector of MyStruct
|
| |