C++ – In which scenario do I use a particular STL container

ccontainer-data-typestl

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 own specific properties, and I'm close to memorizing all of them… But what I do not yet grasp is in which scenario each of them is used.

What is the explanation? Example code is much prefered.

Best Answer

This cheat sheet provides a pretty good summary of the different containers.

See the flowchart at the bottom as a guide on which to use in different usage scenarios:

http://linuxsoftware.co.nz/containerchoice.png

Created by David Moore and licensed CC BY-SA 3.0