Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::split: how to split a string with a character?

Tags:

c++

I'm stuck with this simple problem. Say I have a string which is consisted from characters [0-9]. What I would like to do is split the string by the single characters using boost::split.

std::string str = "0102725";
std::vector<std::string> str2;
boost::split(str2, str, boost::is_any_of(SOMETHING));

I'm looking for SOMETHING so that str2[0] contains "0", str2[1] contains "1", str2[2] contains "0" and so on. So far I have tried "", ':' and ":" but no luck...

like image 706
cheese55 Avatar asked Dec 28 '22 17:12

cheese55


1 Answers

boost::split is overkill for that.

for (size_t i=0; i < str.length(); i++)
  str2.push_back(std::string(1, str.at(i)));
like image 171
Mat Avatar answered Dec 30 '22 07:12

Mat