Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
STL container for storing instances of any data type.
Prefer using a std::vector over an array [1][2][3][4]. You can also create 2-dimensional matrices(or more dimensions).
Advantages of a std::vector over an array are:
#include <iostream> |
Calling std::remove to remove a certain value from a std::vector does not change a std::vector its size. std::remove does return an iterator to where the removed elements are put. This iterator can be used to call std::vector its 'erase' member function. These two operations are called the erase-remove idiom.
Use the erase-remove idiom the really remove a value from a std::vector:
#include <cassert> |
Note that among these are also more general container code snippets.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.