c++ - boost::split 返回 sep 字符

标签 c++ string algorithm boost split

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

最佳答案

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

关于c++ - boost::split 返回 sep 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12208616/

相关文章:

c++ - 将 void* 转换为 std::function<void()>

c++ - GCC C++ 11无法看到#if Windows和#if linux(重新询问)

c++ 一个类可以包含一个与它是 friend 的类成员吗?

c++ - 在 C++ 中从 String 转换为 Double 的奇怪之处

algorithm - 您如何以不可预测的顺序遍历整数范围?

c++ - Qt::FramelessWindowHint setSizeConstraint 对关闭事件的副作用

java - 字符串到映射转换java

javascript - 在 JS 中按类型拆分长度未知的可能相邻元素的字符串

arrays - 计算不适合 RAM 的数组中重复元素的有效算法

algorithm - 欧氏算法的时间复杂度