fork download
  1. #include<iostream>
  2. #include<boost/algorithm/string.hpp>
  3. #include<vector>
  4. #include <map>
  5.  
  6. using namespace std;
  7. using namespace boost::algorithm;
  8.  
  9.  
  10. int main()
  11. {
  12. vector<string> compGrpKey;
  13. map<string, vector<string>> mapCompGroupKey;
  14.  
  15. //declaring the input strings
  16. string str1 = "I am Boost Library";
  17. string str2 = "I am very efficient";
  18. string str3 = "I am very gabbu";
  19.  
  20. split(compGrpKey,str1,[](char c) { return c == ' '; });
  21. mapCompGroupKey["str1"] = compGrpKey;
  22. split(compGrpKey,str2,[](char c) { return c == ' '; });
  23. mapCompGroupKey["str2"] = compGrpKey;
  24. split(compGrpKey,str3,[](char c) { return c == ' '; });
  25. mapCompGroupKey["str3"] = compGrpKey;
  26.  
  27. for(map<string, vector<string> >::const_iterator it = mapCompGroupKey.begin();
  28. it != mapCompGroupKey.end(); ++it)
  29. {
  30. std::cout << it->first << "\n";
  31. for (const auto& value : it->second) {
  32. std::cout << value << '/';
  33. }
  34. std::cout << '\n';
  35. }
  36.  
  37. }
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
str1
I/am/Boost/Library/
str2
I/am/very/efficient/
str3
I/am/very/gabbu/