Marilag Ang Malaya

Saturday, February 7, 2009

From C arrays to C++ vectors

The C++ STL (Standard Template Library) includes some very useful templates. The main idea behind STL is to re-use some of the best implementations of the most common data structures, such as queues, lists, stacks. One of these implementations is the C++ vector.

In C, we could declare an array of integers like this:
int grades[MAX_SIZE];
This statement will still work with C++, and is still valid. However, a more "C++"-centric way of doing the same thing would be to use vectors:
vector<int> grades(MAX_SIZE);
You can still access each element using:
grades[i]
but now you can use STLĀ vector functions.

Labels: , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home