fork download
  1. #include <iostream>
  2. #include <vector>
  3. int main()
  4. {
  5. std::string line = "Number:Description:Price:Weight";
  6.  
  7. std::vector<std::string> vecStrings;
  8. std::string word;
  9. word.clear();
  10.  
  11. size_t count = 0;
  12. for(auto const& it: line)
  13. {
  14. if(it != ':') word += it;
  15.  
  16. if(it == ':' || count + 1 == line.size() )
  17. {
  18. vecStrings.emplace_back(word);
  19. word.clear();
  20. }
  21. ++count;
  22. }
  23. for(const auto& it: vecStrings)
  24. std::cout << it << "\n";
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 4184KB
stdin
Standard input is empty
stdout
Number
Description
Price
Weight