#include <boost/algorithm/string.hpp>            // for is_any_of
#include <boost/range/algorithm/replace_if.hpp> // for replace_if
#include <string>
#include <iostream> std::string someString = "abc.def-ghi";
std::string toReplace = ".-";
std::string processedString =
boost::replace_if(someString, boost::is_any_of(toReplace), ' '); int main()
{
std::cout << processedString;
}
This modifies the original, so if you need to keep it, you can use boost::replace_copy_if: #include <boost/algorithm/string.hpp>
#include <boost/range/algorithm/replace_copy_if.hpp>
#include <string>
#include <iostream>
#include <iterator> // for back_inserter std::string someString = "abc.def-ghi";
std::string toReplace = ".-"; int main()
{
std::string processedString;
boost::replace_copy_if(someString,
std::back_inserter(processedString), boost::is_any_of(toReplace), ' ');
std::cout << processedString;
}

replace_all_regex_copy

#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp> int main(int argc, char** argv) {
std::string someString = "abc.def-ghi";
std::cout << someString << std::endl;
std::string toReplace = "[.-]"; // character class that matches . and -
std::string replacement = " ";
std::string processedString =
boost::replace_all_regex_copy(someString, boost::regex(toReplace), replacement);
std::cout << processedString << std::endl;
return 0;
}

boost replace_if replace_all_regex_copy用法的更多相关文章

  1. boost::function的用法

    本片文章主要介绍boost::function的用法. boost::function 就是一个函数的包装器(function wrapper),用来定义函数对象. 1.  介绍 Boost.Func ...

  2. boost::bind 和 boost::function 基本用法

    这是一篇介绍bind和function用法的文章,起因是近来读陈硕的文章,提到用bind和function替代继承,于是就熟悉了下bind和function的用法,都是一些网上都有的知识,记录一下,期 ...

  3. [转] boost::any的用法、优点和缺点以及源代码分析

    boost::any用法示例: #include <iostream> #include <list> #include <boost/any.hpp> typed ...

  4. [boost] : asser库用法

    基本用法 需要包含头文件#include <boost/assert.hpp> assert库定义了两个断言宏 BOOST_ASSERT BOOSE_ASSERT_MSG 第一种形式等价于 ...

  5. boost bind function用法说明

    目录(?)[+] 1 bind/function 引 (1)头文件 bind函数#include <boost/bind.hpp> function使用头文件#include <bo ...

  6. (转)boost::bind介绍

    转自:http://www.cnblogs.com/sld666666/archive/2010/12/14/1905980.html 这篇文章介绍boost::bind()的用法, 文章的主要内容是 ...

  7. boost function对象

    本文根据boost的教程整理. 主要介绍boost function对象的用法. boost function boost function是什么 boost function是一组类和模板组合,用于 ...

  8. boost::function 介绍

    本片文章主要介绍boost::function的用法. boost::function 就是一个函数的包装器(function wrapper),用来定义函数对象. 1.  介绍 Boost.Func ...

  9. boost::bind 介绍

    boost::bind 介绍   这篇文章介绍boost::bind()的用法, 文章的主要内容是参考boost的文档. 1. 目的 boost::bind 是std::bindlist 和 std: ...

随机推荐

  1. 【CSS】使用CSS控制文字过多自动省略号

    使用CSS可以设置一下样式: <style> u,small{ overflow: hidden; text-overflow: ellipsis; display: -webkit-bo ...

  2. 使用find命令查找Linux中的隐藏文件的方法

    我们可以在Linux 或者 Unix 系统上使用 find 命令去查询所有(全部)隐藏文件 基本语法如下: 复制代码 代码如下: [root@dabu.info ~]#find /要查找的文/件/夹/ ...

  3. 第七讲_图像描述(图说)Image Captioning

    第七讲_图像描述(图说)Image Captioning 本章结构 递归神经网络 时序后向传播(BPTT) 朴素Vanilla-RNN 基本模型 用sigmoid存在严重的梯度消失 LSTM长短时记忆 ...

  4. innerHTML outerHTML innerText

      迁移时间--2017年10月31日14:52:59 Author:Marydon UpdateTime--2017年1月15日20:33:03innerHTML,outerHTML与innerTe ...

  5. Something about cache

    http://www.tyut.edu.cn/kecheng1/2008/site04/courseware/chapter5/5.5.htm 5.5 高速缓冲存储器cache 随着CPU时钟速率的不 ...

  6. Terminal emulator

    http://en.wikipedia.org/wiki/Terminal_emulator Terminal emulator From Wikipedia, the free encycloped ...

  7. 「零秒思考」是个神话,不过这款笔记术你值得拥有zz

    今天读完了赤羽雄二的<零秒思考>,作者是一位在麦肯锡公司工作了 14 年的资深顾问.依照作者的说法,「零秒思考」指的是: 瞬间便能认清现状, 瞬间便能整理问题, 瞬间便能考虑出解决办法, ...

  8. c和c++的输入输出

    格式输出:  printf(格式控制, 输出表列); %d 十进制数  %md m为指定的宽度 若数据位数小于m,则左端补以空格;若大于m,则按实际位数输出 %ld 长整型数据  %mld 指定字段宽 ...

  9. Django中的模板和分页

    模板 在Templates中添加母版: - 母版...html 母版(master.html)中可变化的地方加入: {%block content%}{%endblock%} 在子版 (usermg. ...

  10. python发送邮件相关问题总结

    一.发送邮件报错:554:DT:SPM 1.报错信息 2.通过查找163报错信息页面,554 DT:SPM的问题如下: 3.将邮件主题中的“test”去除,经过测试,实际上邮件主题包含“test”也能 ...