• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >C语言 > C++之BOOST字符串查找示例

C++之BOOST字符串查找示例

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-28

通过本文主要向大家介绍了c++ boost,c++ boost库,boost c++ libraries,c++如何输入字符串,c++数字转字符串等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了C++中BOOST字符串查找的方法,分享给大家供大家参考。具体方法如下:

BOOST  字符串查找示例

#include <iostream> 
#include <algorithm> 
#include <functional> 
#include <boost/algorithm/string/case_conv.hpp> 
#include <boost/algorithm/string/find.hpp> 
 
using namespace std; 
using namespace boost; 
 
int main() 
{   
    cout << "* Find Example *" << endl << endl; 
 
    string str1("abc___cde___efg"); 
    string str2("abc"); 
 
    // find "cde" substring 
    iterator_range<string::iterator> range=find_first( str1, string("cde") ); 
 
    // convert a substring to upper case  
    // note that iterator range can be directly passed to the algorithm 
    to_upper( range ); 
 
    cout << "str1 with upper-cased part matching cde: " << str1 << endl; 
 
    // get a head of the string 
    iterator_range<string::iterator> head=find_head( str1, 3 ); 
    cout << "head(3) of the str1: " << string( head.begin(), head.end() ) << endl; 
 
    // get the tail 
    head=find_tail( str2, 5 ); 
    cout << "tail(5) of the str2: " << string( head.begin(), head.end() ) << endl; 
 
    // char processing 
    char text[]="hello dolly!"; 
    iterator_range<char*> crange=find_last(text,"ll"); 
 
    // transform the range ( add 1 ) 
    transform( crange.begin(), crange.end(), crange.begin(), bind2nd( plus<char>(), 1 ) ); 
    // uppercase the range 
    to_upper( crange ); 
 
    cout << text << endl; 
 
    cout << endl; 
 
    return 0; 
}</div>

boost 判定函数的使用

#include <iostream> 
#include <functional> 
#include <boost/algorithm/string/predicate.hpp> 
#include <boost/algorithm/string/classification.hpp> 
#include <boost/bind.hpp> 

using namespace std; 
using namespace boost; 

int main() 
{ 
    cout << "* Predicate Example *" << endl << endl; 
 
    string str1("123xxx321"); 
    string str2("abc"); 
 
    // Check if str1 starts with '123' 
    cout << "str1 starts with \"123\": " <<  
        (starts_with( str1, string("123") )?"true":"false") << endl;  
     
    // Check if str1 ends with '123' 
    cout << "str1 ends with \"123\": " <<  
        (ends_with( str1, string("123") )?"true":"false") << endl;  
 
    // Check if str1 containes 'xxx' 
    cout << "str1 contains \"xxx\": " <<  
        (contains( str1, string("xxx") )?"true":"false") << endl;  
 
    // Check if str2 equals to 'abc' 
    cout << "str2 equals \"abc\": " <<  
        (equals( str2, string("abc") )?"true":"false") << endl;  
 
    // Classification functors and all predicate 
    if ( all(";.,", is_punct() ) ) 
    { 
        cout << "\";.,\" are all punctuation characters" << endl;   
    } 
 
    // Classification predicates can be combined  
    if ( all("abcxxx", is_any_of("xabc") && !is_space() ) ) 
    { 
        cout << "true" << endl; 
    } 
 
    cout << endl; 
 
    return 0; 
}</div>

boost替换示例

#include <iostream> 
#include <iterator> 
//#include <boost/algorithm/string/replace.hpp> 
//#include <boost/algorithm/string/erase.hpp> 
//#include <boost/algorithm/string/case_conv.hpp> 
#include <boost/algorithm/string.hpp> 
 
//Following two includes contain second-layer function. 
//They are already included by first-layer header 
 
//#include <boost/algorithm/string/replace2.hpp> 
//#include <boost/algorithm/string/find2.hpp> 
 
using namespace std; 
using namespace boost; 
 
// uppercase formatter 
/* 
    Convert an input to upper case.  
    Note, that this formatter can be used only on std::string inputs. 
*/ 
inline string upcase_formatter(  
    const iterator_range<string::const_iterator>& Replace ) 
{ 
    string Temp(Replace.begin(), Replace.end()); 
    to_upper(Temp); 
    return Temp; 
} 
 
int main() 
{   
    cout << "* Replace Example *" << endl << endl; 
 
    string str1("abc___cde___efg"); 
 
    // Erase 6-9th characters from the string 
    cout << "str1 without 6th to 9th character:" << 
        erase_range_copy( st

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • C++ boost 时间与日期处理详细介绍
  • C++中Boost库裁剪与其应用详解
  • C++之BOOST字符串查找示例
  • C++之Boost::array用法简介
  • C++之boost::array的用法

相关文章

  • 2017-05-28C语言编程中生成随机数的入门教程
  • 2017-05-28如何查看进程实际的内存占用情况详解
  • 2017-05-28linux C++ 获取文件绝对路径的实例代码
  • 2017-05-28C++ 如何用cout输出hex,oct,dec的解决方法
  • 2017-05-28基于C++字符串替换函数的使用详解
  • 2017-05-28C++多线程编程时的数据保护
  • 2017-05-28C++ 将文件数据一次性加载进内存实例代码
  • 2017-05-28指向类成员函数的指针其实并非指针
  • 2017-05-28扩展KMP算法(Extend KMP)
  • 2017-05-28简单比较C语言中的execl()函数与execlp()函数

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • C语言中网络地址与二进制数之间转换的函数小结
    • 探究在C++程序并发时保护共享数据的问题
    • 用C++实现队列的程序代码
    • C++基于栈实现铁轨问题
    • C++实现的分布式游戏服务端引擎KBEngine详解
    • C++内存查找实例
    • 用C语言判断字符是否为空白字符或特殊字符的方法
    • C语言中的abs()函数和exp()函数的用法
    • 针对Ruby的Selenium WebDriver安装指南
    • 深入分析C语言分解质因数的实现方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有