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. To be also able to read the std::vector, go to write and read a std::vector to/from a std::stream.
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.