fork(1) download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <string>
  4. #include <algorithm>
  5. #include <map>
  6.  
  7. template <typename T, typename U>
  8. struct Pair : std::pair<T, U>
  9. {
  10. using std::pair<T, U>::pair;
  11.  
  12. friend std::ostream& operator<<(std::ostream& os, const Pair& p) {
  13. return os << p.first << ' ' << p.second;
  14. }
  15.  
  16. friend std::istream& operator>>(std::istream& is, Pair& p) {
  17. return is >> p.first >> p.second;
  18. }
  19. };
  20.  
  21. int main()
  22. {
  23. std::map<std::string, int> map;
  24.  
  25. using pair_t = Pair<std::string, int>;
  26. using input = std::istream_iterator<pair_t>;
  27. using output = std::ostream_iterator<pair_t>;
  28.  
  29. std::copy(input(std::cin), input(), std::inserter(map, map.begin()));
  30. std::copy(map.begin(), map.end(), output(std::cout, "\n"));
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3484KB
stdin
Hello 1 beatiful 2 world 3
stdout
Hello 1
beatiful 2
world 3