I\'ve been reading up on STL containers in my book on C++, specifically the section on the STL and its containers. Now I do understand each and every one of them have their
An important point only briefly mentioned so far, is that if you require contiguous memory (like a C array gives), then you can only use vector
, array
, or string
.
Use array
if the size is known at compile time.
Use string
if you only need to work with character types and need a string, not just a general-purpose container.
Use vector
in all other cases (vector
should be the default choice of container in most cases anyway).
With all three of these you can use the data()
member function to get a pointer to the first element of the container.