Created
April 19, 2016 21:56
-
-
Save ivan-krukov/86db00169355b80ed92ee5feb9509785 to your computer and use it in GitHub Desktop.
Print vectors in C++, easy as `cout << vector << endl`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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