fork(12) download
  1. #include <iterator>
  2. #include <sstream>
  3. #include <iostream>
  4. #include <string>
  5. #include <map>
  6.  
  7. namespace std {
  8. istream& operator >> (istream& is, pair<string, string>& ps)
  9. {
  10. return is >> ps.first >> ps.second;
  11. }
  12. ostream& operator << (ostream& os, const pair<const string, string>& ps)
  13. {
  14. return os << ps.first << "==>>" << ps.second;
  15. }
  16. }
  17.  
  18. int main() {
  19. std::string file = "one two three four five six seven eight";
  20. std::istringstream is(file);
  21. std::map<std::string, std::string> mps;
  22.  
  23. std::insert_iterator< std::map<std::string, std::string> > mpsi(mps, mps.begin());
  24.  
  25. const std::istream_iterator<std::pair<std::string,std::string> > eos;
  26. std::istream_iterator<std::pair<std::string,std::string> > its (is);
  27.  
  28. std::copy(its, eos, mpsi);
  29.  
  30. std::copy(mps.begin(), mps.end(), std::ostream_iterator<std::pair<std::string,std::string> >(std::cout, "\n"));
  31. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
five==>>six
one==>>two
seven==>>eight
three==>>four