fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <map>
  5.  
  6.  
  7. int main() {
  8. std::map<std::string,std::string> dictionary;
  9. std::istream& in = std::cin;
  10.  
  11. std::string line;
  12. while(getline(in, line)) { // Read whole lines first ...
  13. std::istringstream iss(line); // Create an input stream to read your values
  14. std::string english; // Have variables to receive the input
  15. std::string french; // ...
  16. if(iss >> english >> french) { // Read the input delimted by whitespace chars
  17. dictionary[english] = french; // Put the entry into the dictionary.
  18. // NOTE: This overwrites existing values
  19. // for `english` key, if these were seen
  20. // before.
  21. }
  22. else {
  23. // Error ...
  24. }
  25. }
  26.  
  27. for(std::map<std::string,std::string>::iterator it = dictionary.begin();
  28. it != dictionary.end();
  29. ++it) {
  30. std::cout << it->first << " = " << it->second << std::endl;
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 3440KB
stdin
you	vous
today	aujourd'hui
good	bon
good morning	bonjour
afternoon	après-midi
good evening	bonsoir
much	beaucoup
is	 est
stdout
afternoon = après-midi
good = evening
is = est
much = beaucoup
today = aujourd'hui
you = vous