fork(8) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <iterator>
  4. using namespace std;
  5.  
  6. // print a vector
  7. template<typename T1>
  8. std::ostream& operator <<( std::ostream& out, const std::vector<T1>& object )
  9. {
  10. out << "[";
  11. if ( !object.empty() )
  12. {
  13. //std::copy( object.begin(), --object.end(), std::ostream_iterator<T1>( out, ", " ) );
  14. for(typename std::vector<T1>::const_iterator t = object.begin(); t != object.end() - 1; ++t) {
  15. out << *t << ", ";
  16. }
  17. out << *--object.end(); // print the last element separately to avoid the extra characters following it.
  18. }
  19. out << "]";
  20. return out;
  21. }
  22.  
  23. int main()
  24. {
  25. vector<vector<int> > a;
  26. vector<int> b;
  27. //cout << b ; // Works fine for this
  28. cout << a; // Compiler error
  29. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
[]