Skip to content

Instantly share code, notes, and snippets.

@ivan-krukov
Created April 19, 2016 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan-krukov/86db00169355b80ed92ee5feb9509785 to your computer and use it in GitHub Desktop.
Save ivan-krukov/86db00169355b80ed92ee5feb9509785 to your computer and use it in GitHub Desktop.
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