2017-10-13 103 views
-2

我有這樣的字符串:分裂串 '' 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

回答

0
#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