The provided answer by filmor is correct, but as others have already stated in the comments: If you really want to learn C++11 you should use a container like std::vector
.
For example:
std::vector<std::vector<int>> list;
And you're done. You can add as many int
s as you like. If you want to have a fixed size list of dynamic int-lists, consider using std::array
:
std::array<std::vector<int>, 10> arr;
Although I would always recommend using std::vector
if performance or memory is not an issue. You have to make sure you're not exceeding the maximum number of elements anyway.
Concerning the for
-loop, I would always try to use it this way:
for (auto &item : list)
If you don't want to modify the list, add const
:
for (const auto &item : list)
Even if you don't want to modify the list, you're not making copies as you progress through it.