fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. void splitString(string str, char delimiter, vector<string> * out) {
  7. string word_buffer;
  8. for (string::size_type i = 0; i < str.length(); ++i) {
  9. if (str[i] == delimiter) {
  10. out->push_back(word_buffer);
  11. word_buffer.clear();
  12. } else {
  13. word_buffer.push_back(str[i]);
  14. }
  15. }
  16. if (!word_buffer.empty())
  17. out->push_back(word_buffer);
  18. }
  19.  
  20. int main() {
  21. vector<string> user_input_tokens;
  22. string port = "209,202,252,54,19,15";
  23. splitString(port, ',', &user_input_tokens);
  24. for (string str : user_input_tokens) {
  25. cout << str << ".";
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
209.202.252.54.19.15.