我有这个代码:
#include <boost/tokenizer.hpp>
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
int main() {
using namespace std;
boost::char_separator<char> sep(",");
string s1 = "hello, world";
tokenizer tok1(s1, sep);
for (auto& token : tok1) {
cout << token << " ";
}
cout << endl;
tokenizer tok2(string("hello, world"), sep);
for (auto& token : tok2) {
cout << token << " ";
}
cout << endl;
tokenizer tok3(string("hello, world, !!"), sep);
for (auto& token : tok3) {
cout << token << " ";
}
cout << endl;
return 0;
}
此代码产生以下结果:
hello world
hello
hello world !!
显然,第二行是错误的。hello world
相反,我期待着。问题是什么?