分裂串 '' C++
问题描述:
答
#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
的['的std :: getline'](http://en.cppreference.com/w/cpp/ string/basic_string/getline)函数实际上可以使用任意字符作为“行尾”,而不仅仅是换行符。它可以和['std :: istringstream'](http://en.cppreference.com/w/cpp/io/basic_istringstream)一起用于这种字符串“分割”。 –
因为你正在寻找'string :: find_first_of'这个东西的第一个东西,所以它是一个很好的匹配;) – pergy