[noob][c++] what is a container?

what is a container?
TroudeloupAsked:
Who is Participating?
 
AxterConnect With a Mentor Commented:
Example containers:
std::vector
std::list
std::deque
std::map
std::set

Some would also consider std::string a container.
0
 
cuziyqConnect With a Mentor Commented:
A container is a set of data wrapped up in a class.  A linked list is an example of a container class.
0
 
AxterConnect With a Mentor Commented:
A container is a class that stores multiple objects of the same type.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
itsmeandnobodyelseConnect With a Mentor Commented:
To add to above information:

By using template containers you can store any arbitrary type. The most used container class is std::vector which is a dynamic array class. A special and very useful container is std::map whic is a so-called dictionary. A dictionary has a key and data type, which were stored as a pair. A dictionary provides a fast access to the data via the key.

Regards, Alex
0
 
AxterCommented:
FYI:
Many developer make the mistake of using std::list as they're default container.
For most requirements std::vector is more efficient then std::list.
Moreover, the C++ standard recommends using std::vector as the default container.

In general, std::list should only be used when you need to remove or add content from the center of the container.

std::deque should be used if you need to add or remove content from the start (beginning) of the container, but don't need to add/remove content from the center.

std::vector should be the default container, since for most requirements, you only need to add/remove content from the end of the container.

Some experts recommend using std::vector, even when you need to add/content from the start or middle of the container when the add/remove action is not accessive.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.