fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <map>
  4. #include <string>
  5.  
  6.  
  7. int main()
  8. {
  9. std::map<std::string, int> dictionary;
  10. //std::ifstream input("fruits.txt");
  11. std::string word;
  12. while (std::cin >> word)
  13. dictionary[word]++;
  14. for(const auto& e: dictionary)
  15. std::cout << e.first << ": " << e.second << '\n';
  16. }
Success #stdin #stdout 0s 3436KB
stdin
apple
apple
orange
red
red
red
stdout
apple: 2
orange: 1
red: 3