Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
std::vector code snippet to write every element in a std::vector to std::cout. There is also a more general solution for every container: CoutContainer.
Instead of using a for-loop (See question 15 of Exercise #9: No for-loops), the algorithm std::copy can be used to copy the contents of a std::vector to std::cout using the std::ostream_iterator. Prefer algorithms over loops [1][2].
#include <vector> |
#include <vector> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.