boost :: split返回sep字符

时间:2012-08-31 03:43:21

标签: c++ string algorithm boost split

我正在使用boost::split(lines, str, boost::is_any_of(delims));现在我想知道针对每个拆分找到了哪个delim字符。我会把那个角色放在分裂线的末尾。这样我就可以重新创建原始字符串。我已经搜索过但在boost::split中没有找到任何此类功能我是否需要使用其他任何功能?

1 个答案:

答案 0 :(得分:1)

mb boost::tokenizerboost::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