我正在使用 boost::split(lines, str, boost::is_any_of(delims));
现在我想知道针对每个拆分找到了哪个 delim 字符。我会把那个字符放在分割线的末尾。这样我就可以重新创建原始字符串。我搜索过但没有在 boost::split
中找到任何此类功能我需要使用任何其他功能吗?
最佳答案
mb boost::tokenizer
与 boost::char_separator
?
http://www.boost.org/doc/libs/1_51_0/libs/tokenizer/char_separator.htm
例子。
#include <iostream>
#include <string>
#include <boost/tokenizer.hpp>
int main()
{
std::string str = "hello, and what do. you? want";
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("", " ,.?");
tokenizer tokens(str, sep);
for (tokenizer::iterator pos = tokens.begin(); pos != tokens.end(); ++pos)
{
std::cout << *pos << std::endl;
}
}
http://liveworkspace.org/code/8dca20ecaa017000dd67096fc5d20aeb
关于c++ - boost::split 返回 sep 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12208616/