#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. angular http ajax header

    myAppModule.config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.headers.common ...

  2. 系统网站架构(淘宝、京东)& 架构师能力

    来一张看上去是淘宝的架构的图: 参考地址:http://hellojava.info/?p=520 说几点我认可的地方: 架构需要掌握的点: 通信连接方式:大量的连接通常会有两种方式: 1. 大量cl ...

  3. 【HDOJ 5371】 Hotaru&#39;s problem

    [HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...

  4. TNS-01201: Listener cannot find executablen 错误

    近期在启动监听器的时候收到了TNS-01201: Listener cannot find executable...的错误提示.这个错误还真是一个一直没有碰到过的错误.咋一看还真不明确是怎么一回事呢 ...

  5. mini2440使用jlink烧写superboot到norflash

    Jlink版本号:J-flash ARM V4.12                    J-Flash ARM的配置. 一般说来file-->open project里面会找到一些*.jfl ...

  6. Android gdb so

    gdb debug an android application 1.gdb 要有gdbserver 一般模拟器默认装有gdbserver,如2.3.3的模拟器,看一下有没有: D:\Develope ...

  7. [GUIDE] How to Setup Ubuntu 16.04 LTS Xenial Xerus for Compiling Android ROMs

    With a new version of Ubuntu comes an update to my guide for setting up a build environment to compi ...

  8. Sass编译css/Grunt压缩文件

    Sass安装(mac) $ sudo gem install sass scss编译成css文件 $ sass ui.scss ui.css CLI安装 $ npm install -g grunt- ...

  9. BZOJ 4316: 小C的独立集 仙人掌 + 树形DP

    4316: 小C的独立集 Time Limit: 10 Sec  Memory Limit: 128 MB Description 图论小王子小C经常虐菜,特别是在图论方面,经常把小D虐得很惨很惨. ...

  10. EasyDarwin手机直播转发快速显示问题之音频处理过程

    前言 在我们前面一篇<EasyDarwin手机直播是如何实现的快速显示视频的方法>中,我们描述到了EasyDarwin流媒体服务器端是如何对视频H.264进行缓冲,再以最快的方式将最新的视 ...