Solved

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

Posted on 2007-11-16
6
195 Views
Last Modified: 2010-04-01
what is a container?
0
Comment
Question by:Troudeloup
6 Comments
 
LVL 14

Assisted Solution

by:cuziyq
cuziyq earned 100 total points
ID: 20299637
A container is a set of data wrapped up in a class.  A linked list is an example of a container class.
0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 250 total points
ID: 20299657
A container is a class that stores multiple objects of the same type.
0
 
LVL 30

Accepted Solution

by:
Axter earned 250 total points
ID: 20299666
Example containers:
std::vector
std::list
std::deque
std::map
std::set

Some would also consider std::string a container.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 150 total points
ID: 20299695
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
 
LVL 30

Expert Comment

by:Axter
ID: 20300263
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
 

Author Comment

by:Troudeloup
ID: 20300540
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 164
trigs fail! I thought I knew how to do trignometry 3 76
Android development question 2 55
C++ help/ Toy problem 19 31
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question