Boost之string处理篇(一)

Boost之string处理篇
#include <iostream>
#include <string>
#include <vector>
#include <boost\lexical_cast.hpp>
#include <boost\algorithm\string.hpp>
using namespace std;
using namespace boost;


void string_trans_other();     // int、double、string类型的数据转换
void string_handler_sub();     //结尾判断、string大小写转换、替换某个字符串
void enum_handler_sub();       //枚举处理


int main()
{
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>//string_trans_other();
<span style="white-space:pre">	</span>string_handler_sub();
<span style="white-space:pre">	</span>//enum_handler_sub();
<span style="white-space:pre">	</span>getchar();


return 0;
}
void string_trans_other()
{
<span style="white-space:pre">	</span>int a = lexical_cast<int>("123");            //从string---int
<span style="white-space:pre">	</span>double b = lexical_cast<double>("123.23");   //从string---double


<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>const double d = 123.33;
<span style="white-space:pre">	</span>string ss = lexical_cast<string>(d);
}
void string_handler_sub()
{
<span style="white-space:pre">	</span>string str_aa("11readme.txt");
<span style="white-space:pre">	</span>if(ends_with(str_aa,"txt"))       //ends_with判断一个字符串是不是以什么结尾
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>to_upper(str_aa);             //to_upper(string) 变为大写
<span style="white-space:pre">		</span>cout<<"1:"<<str_aa<<endl;
<span style="white-space:pre">		</span>string str_aa("readme.txt");
<span style="white-space:pre">		</span>cout<<"2:"<<to_upper_copy(str_aa)+"UPPER"<<endl;
<span style="white-space:pre">		</span>assert(ends_with(str_aa,"txt"));
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>replace_first(str_aa,"README","followme");//replace_first替换功能
<span style="white-space:pre">	</span>cout<<"3:"<<str_aa<<endl;


<span style="white-space:pre">	</span>vector<char> char_v(str_aa.begin(),str_aa.end());
<span style="white-space:pre">	</span>vector<char> char_v2 = to_upper_copy(
<span style="white-space:pre">	</span>erase_first_copy(char_v,"txt"));
<span style="white-space:pre">	</span>for (int i =0 ; i < char_v2.size(); ++i)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>cout<<char_v2[i];
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>string str_bb ("I love you .");
<span style="white-space:pre">	</span>string str_bb_up = to_upper_copy(str_bb);//全部转成大写
<span style="white-space:pre">	</span>string str_bb_low = to_lower_copy(str_bb);//全部转成小写
<span style="white-space:pre">	</span>


}


void enum_handler_sub()
{
<span style="white-space:pre">	</span>enum room_brother_name {
<span style="white-space:pre">	</span>Xuxin    = 1,
<span style="white-space:pre">	</span>Xujingli = 2,
<span style="white-space:pre">	</span>Liuzibin = 3,
<span style="white-space:pre">	</span>Jiyanghongkang = 4
<span style="white-space:pre">	</span>}wh;
<span style="white-space:pre">	</span>wh = Xuxin;   //定义一个枚举
<span style="white-space:pre">	</span>cout<<"the value is :"<<wh<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值