Whenever possible, you should use lists instead of arrays. This chapter introduces containers and discusses various ways of grouping things in lists and how to iterate through them.
There are many occasions when it is necessary to deal with collections of things. The classic approach in languages like C is to use arrays (Section 21.4) to store such collections. In C++, arrays are regarded as evil.
Following are a few good reasons to avoid using arrays in C++:
• Neither the compiler nor the runtime system checks array subscripts to make sure that they are within the correct range.
• A programmer using an array has the responsibility to write extra code to do the range checking.
• Arrays are either ...