Możesz użyć Boost.Algorithm lub Boost.Tokenizer
string str = "1,2,34,56,7";
vector<string> ret;
boost::algorithm::split(ret,str,bind(equal_to<char>(),',',placeholders::_1));
string str = "1,2,34,56,7";
boost::tokenizer<boost::char_separator<char>>(str,boost::char_separator<char>(","))
http://melpon.org/wandbox/permlink/y159GnPZugc4I3gX
Możesz użyć biblioteki standardowej:
regex: http://melpon.org/wandbox/permlink/5UOfIRxzURiS52M7
string str = "1,2,34,56,7";
regex rx{R"(\d+)"};
auto b = sregex_iterator(begin(str), end(str), rx);
auto e = sregex_iterator();
for(auto i = b; i != e; ++i){
DBG(i->str());
}
lub bardziej prymitywnych narzędzi, takich jak scanf
(musisz wiedzieć dokładnie ile liczb)/strtok
(nie możesz użyć argumentów main bezpośrednio)/czy stringstreamy (uważaj jakie znaki ignorujesz), zapewne opisanych w postach powyżej.
Jeśli używasz Qt możesz użyć po prostu QString::split
:
QString str = "1,2,34,56,7";
for(auto const& s : str.split(",")){
DBG(s.toStdString());
}