Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Print vectors in C++, easy as `cout << vector << endl`
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
typename vector<T>::const_iterator it;
for (it = v.begin(); it != v.end() - 1; ++it) {
os << *it << ", ";
os << *(it) << "]";
return os;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.