分裂串 '' C++

问题描述:

我有这样的字符串:分裂串 '' C++

17, the day is beautiful , day

。 我想在第一个','中分割这个字符串。 例如,我想要2个字符串。一个用于和两个为天是美,日

+0

的['的std :: getline'](http://en.cppreference.com/w/cpp/ string/basic_string/getline)函数实际上可以使用任意字符作为“行尾”,而不仅仅是换行符。它可以和['std :: istringstream'](http://en.cppreference.com/w/cpp/io/basic_istringstream)一起用于这种字符串“分割”。 –

+0

因为你正在寻找'string :: find_first_of'这个东西的第一个东西,所以它是一个很好的匹配;) – pergy

#include <boost/algorithm/string.hpp> 
std::vector<std::string> strs; 
boost::split(strs, "17, 132, asdasd, 111", boost::is_any_of(",")); 
+0

我有两个例子''',但我只想为第一个分割。 在你的例子中,我想在矢量17和132中使用2个元素,asdasd,111 – Roka