fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <sstream>
  5.  
  6. std::vector<std::string> parse(const char* cmd, int length)
  7. {
  8. std::vector<std::string> arguments;
  9. std::istringstream iss(std::string(cmd, length));
  10. std::string s;
  11. while (iss >> s) {
  12. arguments.push_back(s);
  13. }
  14. return arguments;
  15. }
  16.  
  17. int main()
  18. {
  19. const char cmd[] = "param1 param2 param3";
  20. std::vector<std::string> args = parse(cmd, sizeof(cmd)-1);
  21. for(auto &s : args)
  22. std::cout << s << std::endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 4480KB
stdin
Standard input is empty
stdout
param1
param2
param3