fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. unordered_map<string, string> umap;
  5.  
  6. void split(const std::string &line, char sep, int index)
  7. {
  8. std::size_t start = 0, end = 0;
  9. char ch = index + '0';
  10. string key("");
  11. while ((end = line.find(sep, start)) != std::string::npos)
  12. {
  13. key += ch;
  14. ch++;
  15. //key = ch++ + index;
  16. cout<<key<<endl;
  17. cout<<line.substr(start, end - start)<<endl;
  18. //umap.insert(make_pair<string, string>(key, line.substr(start, end - start)));
  19. //tokens.push_back(text.substr(start, end - start));
  20. start = end + 1;
  21. }
  22. string str = ""+ ch + index;
  23. cout<<str<<endl;
  24. cout<<line.substr(start, end - start)<<endl;
  25. //tokens.push_back(text.substr(start));
  26. // return tokens;
  27. }
  28.  
  29. int main()
  30. {
  31. int idx = 0;
  32. vector<string>v = { { "This is Test" },
  33. { "sameple data"} };
  34.  
  35. for(int i =0; i<v.size(); i++)
  36. {
  37. split(v[i], '\t', idx);
  38. }
  39.  
  40. for(auto i: umap)
  41. {
  42. cout<<i.first<<" "<<i.second<<endl;
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0s 5552KB
stdin
Standard input is empty
stdout
0
This
01
is
ch is %zu)
Test
0
sameple
ich is %zu)
data