摘要: BOOST_ASSERT在debug模式下有效。#include #include using namespace std;using namespace boost;double fun(int x){ BOOST_ASSERT(x!=0 && "divede by zero"); return 1.0/x;}int main(){ fun(0); return 0;}获取更多的诊断信息:#include #include #include using namespace std;using namespace boost;#define BOOST_EN 阅读全文
posted @ 2013-08-16 15:01 l851654152 阅读(326) 评论(0) 推荐(0) 编辑
摘要: 正则表示主要用于查找一系列符合规则的对象,而我们之前的查找是对某一特定的字符串进行查找。#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 阅读(2296) 评论(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) 编辑