fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iterator>
  5. #include <algorithm>
  6. #include <sstream>
  7. #include <map>
  8.  
  9. using namespace std;
  10.  
  11. int main() {
  12. map<string, vector<string>> m {
  13. {"a", {"1", "2"}},
  14. {"b", {"1", "2"}},
  15. {"b", {"1", "2"}},
  16. };
  17.  
  18. transform(begin(m), end(m), ostream_iterator<string>(cout), [](auto& p){
  19. stringstream ss;
  20. ss << p.first << ", {";
  21. bool first = true;
  22. for (auto& s : p.second)
  23. {
  24. ss << (first ? "" : ", ") << s;
  25. first = false;
  26. }
  27. ss << "}\n";
  28. return ss.str();
  29. });
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
a, {1, 2}
b, {1, 2}