fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <set>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main() {
  8. map<string, set<string>> data;
  9. data["Key1"].emplace("hello");
  10. data["Key1"].emplace("world");
  11. data["Key1"].emplace("test");
  12. data["Key2"].emplace("Ciao");
  13. data["Key2"].emplace("Mondo");
  14.  
  15. for (const auto& x : data) {
  16. cout << x.first << ": ";
  17. bool first = true;
  18. for (const auto& s : x.second) {
  19. if (!first) {
  20. cout << ", ";
  21. } else {
  22. first = false;
  23. }
  24. cout << s;
  25. }
  26.  
  27. cout << endl;
  28. }
  29.  
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
Key1: hello, test, world
Key2: Ciao, Mondo