上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 24 下一页
摘要: 正则表示主要用于查找一系列符合规则的对象,而我们之前的查找是对某一特定的字符串进行查找。#include #include #include #include using namespace std;using namespace boost;using namespace boost::xpressive;int main(){ string str; cregex reg = cregex::compile("a.c"); if (regex_match("abc",reg)) { cout << "Ok"<&l 阅读全文
posted @ 2013-08-16 13:57 l851654152 阅读(497) 评论(0) 推荐(0) 编辑
摘要: string_algo是用于处理字符串查找,替换,转换等一系列的字符串算法前缀i:表示大小写不敏感后缀_copy:表示不变动输入,返回处理结果的拷贝后缀_if:表示算法需要一个判断式的谓词函数对象。#include #include #include #include using namespace std;using namespace boost;int main(){ string str("readme.txt"); if (ends_with(str,"txt"))//判断后缀 { cout v(str.begin(),str.end()); 阅读全文
posted @ 2013-08-16 10:49 l851654152 阅读(2295) 评论(0) 推荐(0) 编辑
摘要: C++标准库中字符串转数值使用函数atoi(),数值转字符串使用printf系列函数。boost中使用转换函数操作符lexical_cast进行转换,实际上是模板函数。自定义类型,要进行转换必须支持输入输出操作符>。#include #include using namespace std;using namespace boost;int main()try{ int x = lexical_cast("100"); long y = lexical_cast("2000L"); float pai = lexical_cast("3. 阅读全文
posted @ 2013-08-16 01:24 l851654152 阅读(543) 评论(0) 推荐(0) 编辑
摘要: 1.noncopyable用于禁止复制和拷贝的类继承。声明拷贝和赋值函数为私有,将运行时的错误转化为编译期的错误。#include #include using namespace std;using namespace boost;class Mynoncopy {public: Mynoncopy(){}private: Mynoncopy(const Mynoncopy&); void operator=(const Mynoncopy&);};class Test:Mynoncopy{};int main(){ Test t1; //Test t2 = t1;//禁止拷 阅读全文
posted @ 2013-08-15 23:17 l851654152 阅读(392) 评论(0) 推荐(0) 编辑
摘要: 讲到内存池我们会想到对对象进行动态分配的过程new包含三个过程1.使用operator new分配内存2.使用placement new 初始化3.返回内存地址。分配内存可以分解成分配内存和获取内存两步,只是一般在一步里进行。一.使用pool类,获取已经分配了的内存#include #include using namespace std;using namespace boost;int main(){ pool p1(sizeof(int)); int *p = (int*)p1.malloc();//返回内存 if (p1.is_from(p) == true) { cout #... 阅读全文
posted @ 2013-08-15 23:08 l851654152 阅读(944) 评论(0) 推荐(0) 编辑
摘要: 内存问题永远是c++中讨论的重要话题1.c98 auto_ptr的实现,auto_ptr的特点是始终只保持一个指针指向对象,若经过赋值或者拷贝之后原指针失效#include using namespace std;templateclass auto_ptr{public: explicit auto_ptr(T* px = 0):m_px(px){} auto_ptr(const auto_ptr& rhs):m_px(rhs.release()) { } auto_ptr& operator=(auto_ptr& rhs) { reset(rhs.release() 阅读全文
posted @ 2013-08-15 13:08 l851654152 阅读(290) 评论(0) 推荐(0) 编辑
摘要: date_time库使用的日期基于格里高利历,支持从1400-01-01到9999-12-31的日期。空的构造函数会创建一个值为not_a_date_time的无效日期;顺序传入年月日值则创建一个对应日期的date对象。#include #define BOOST_DATE_TIME_SOURCE#include using namespace boost::gregorian;using namespace std;using namespace boost;int main(){ date d1;//无效的时间 date d2(2013,8,15);//输入年月日 date d3(201. 阅读全文
posted @ 2013-08-15 09:48 l851654152 阅读(652) 评论(0) 推荐(0) 编辑
摘要: C++一直缺乏对时间和日期的处理能力,一般借助于C的struct tm和time();timer包含三个类其中timer,progress_timer是计时器类,进度指示类是progress_display.1.timer类,内部封装的是std::clock,精度依赖于具体的编译器和操作系统。只能计算从声明对象到对象结束的时间。#include #include using namespace std;using namespace boost;int main(){ timer t; cout #include #include using namespace std;using names 阅读全文
posted @ 2013-08-15 09:31 l851654152 阅读(1174) 评论(0) 推荐(0) 编辑
摘要: ip::tcp的内部类型socket,acceptor以及resolver是TCP通信中最核心的类。1.同步客户端代码:#include #include #include using namespace std;using namespace boost::asio;using namespace boost;int main(){ io_service ios; cout str(100,0); sock.read_some(buffer(str)); cout #include #include using namespace std;using namespace boost::as. 阅读全文
posted @ 2013-08-14 01:27 l851654152 阅读(2529) 评论(0) 推荐(0) 编辑
摘要: 1.定时器的使用,sleep是等待线程,asio封装了操作系统的异步系统调用select,epoll.io_servie 实现了一个任务队列,这里的任务就是void(void)的函数。Io_servie最常用的两个接口是post和run,post向任务队列中投递任务,run是执行队列中的任务,直到全部执行完毕,并且run可以被N个线程调用。Io_service是完全线程安全的队列。#include #include #include #include #include using namespace std;using namespace boost::asio;using namespace 阅读全文
posted @ 2013-08-13 23:37 l851654152 阅读(3595) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 24 下一页