You could do this fairly easily with a stringstream
and getline()
. The split function would look like:
std::vector<std::string> split_string(const std::string & line, char delim = ' ')
{
std::vector<std::string> sep;
std::string token;
std::stringstream ss(line);
while(getline(ss, token, delim))
sep.push_back(token);
return sep;
}
And then you could use it like
int main ()
{
std::vector<std::string> sep = split_string("Name|Phone Number|Account Number|Price|Tariff|6079777", '|');
for(const auto & e : sep)
std::cout << e << std::endl;
return 0;
}
See this Live Example