fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <string>
  5.  
  6. template< class T >
  7. std::ostream & operator << ( std::ostream & os, const std::vector< T > & v ) {
  8. for ( const auto & i : v ) {
  9. os << i << std::endl;
  10. }
  11. return os;
  12. }
  13.  
  14. template< class K, class V >
  15. std::ostream & operator << ( std::ostream & os, const std::multimap< K, V > & m ) {
  16. for ( const auto & i : m ) {
  17. os << i.first << " : " << std::endl;
  18. os << i.second << std::endl;
  19. }
  20. return os;
  21. }
  22.  
  23. int main() {
  24. std::multimap<int, std::vector< std::string > > m;
  25.  
  26. m.insert(std::make_pair( 1, std::vector< std::string >( {"one", "two", "three" } ) ) );
  27. m.insert(std::make_pair( 10, std::vector< std::string >( {"ten", "twenty", "thirty" } ) ) );
  28. m.insert(std::make_pair( 42, std::vector< std::string >( {"foutry", "two" } ) ) );
  29.  
  30. std::cout << m;
  31. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
1 : 
one
two
three

10 : 
ten
twenty
thirty

42 : 
foutry
two