0
string ss = "1-1-10-8-9";

There is a string like above. I want to add element to string array between "-"

string vector should be same as below

vector<string> str = {"1", "1", "10", "8", "9"};
  • 1
    Does this answer your question? [Parse (split) a string in C++ using string delimiter (standard C++)](https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c) – fas May 26 '20 at 20:28
  • 1
    Does this answer your question? [Splitting a string by a character](https://stackoverflow.com/questions/10058606/splitting-a-string-by-a-character) – Jan Schultke May 26 '20 at 20:28

1 Answers1

-1
#include <iostream>
#include <sstream>
#include <vector>

int main() {

  std::stringstream ss("1-1-10-8-9");

  std::vector<std::string> v;
  std::string s;
  while(std::getline(ss, s, '-')) {
    v.push_back(s);
  }

  return 0;
}
triclosan
  • 5,578
  • 6
  • 26
  • 50