01 2011 档案

vs2005下的dirent.h
摘要:dirent.h是gcc下的一个头文件,而在VS2005中是没有的。这个文件中封装了几个对目录进行操作函数:static DIR *opendir (const char *dirname);static struct dirent *readdir (DIR *dirp);static int closedir (DIR *dirp);对于在linux->windows之间进行程序移植来讲常常会造成一些困扰,在网上仔细搜了一下,发现原来已经有位好同志写了相应的移植代码,如下所示:typedef struct dirent { /* name of current directory e 阅读全文

posted @ 2011-01-31 16:58 几百人有爱 阅读(420) 评论(0) 推荐(0)

boost format 格式控制输出(学习笔记)
摘要:#include #include using namespace boost;using namespace std;// 格式输出控制,(类似c++准准库中的sprintf)// int main(){ // format库的几种用法 //------------------------------------------ // 第一种: // 最接近printf() cout<< "First: " << format("%s: %d + % d = %d/n")%"sum"%1%2%(1+2); // 阅读全文

posted @ 2011-01-28 23:39 几百人有爱 阅读(274) 评论(0) 推荐(0)

boost lexical_cast 字符串数字间的字面转换(学习笔记)
摘要:晕,编译错了#include #include #include /* @brief 实现数字和字符串之间的字面转换 如把123(int)转换成"123"(string) @remark 注意:要转换为数字的字符串不能包含数字、小数点和e/E以外的字符 如:0x100,123L等C++允许的字面数字都不被支持*/using namespace boost;using namespace std;int main(){ //-------------------- // 字符串字面转成数字 //-------------------- int x = lexical_cast 阅读全文

posted @ 2011-01-25 22:46 几百人有爱 阅读(518) 评论(0) 推荐(0)

boost SHA1学习笔记
摘要:#include #include /* @brief SHA1摘要算法:一种很重要的密码学算法,可将任意长度的文本压缩成20个字节的 独一无二的的摘要(uuid名字生成器使用该算法)*/using namespace boost::uuids::detail;using namespace std;int main(){ sha1 sha; // 声明摘要对象 char* szMsg = "This is a short message!"; //-------------------------- // 向摘要压入文本 //----------------------- 阅读全文

posted @ 2011-01-25 21:18 几百人有爱 阅读(517) 评论(1) 推荐(0)

boost uuid 学习笔记
摘要:#include #include #include #include #include using namespace boost::uuids;using namespace std;int main(){ //------------------------- // 一些std函数的应用 //------------------------- vector v(16, 7); uuid u; std::copy(v.begin(), v.end(), u.begin()); // 将一个序列复制到另一个序列中(从begin到end) std::fill_n(u.data + 2, 6, 阅读全文

posted @ 2011-01-25 01:28 几百人有爱 阅读(684) 评论(0) 推荐(0)

lexicographical_compare()按字典序比较函数用法示例(字符串排序)
摘要:#include "algostuff.hpp"using namespace std;void printCollection(const list& l){ PRINT_ELEMENTS(l);}bool lessForCollection(const list& l1,const list& l2){ return lexicographical_compare(l1.begin(),l1.end(),l2.begin(),l2.end());}int main(){ listc1,c2,c3,c4; INSERT_ELEMENTS(c1,1, 阅读全文

posted @ 2011-01-24 00:05 几百人有爱 阅读(470) 评论(0) 推荐(0)

boost exception 学习笔记
摘要:#include #include #include using namespace std;// 从std和boost,新的导常类就同时有它们两的能力struct both_exception: virtual boost::exception, // 这里要用虚继承 virtual std::exception{};// 定义异常both_exception内部异常信息的数据类型// 这样异常信息就可以是各种类型typedef boost::error_info err_str; void stdException(){ try { int err... 阅读全文

posted @ 2011-01-21 22:32 几百人有爱 阅读(462) 评论(0) 推荐(0)

追MM与Java的23种设计模式
摘要:我在Java论坛看到这篇文章,作者以轻松的语言比喻了java的32种模式,有很好的启发作用,但可惜没有给出具体的意思,我就在后边加上了。这些都是最简单的介绍,要学习的话建议你看一下阎宏博士的《Java与模式》一书。 创建型模式 1、FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了。麦当劳和肯德基就是生产鸡翅的Factory 工厂模式:客户类和工厂类分开。消费者任何时候需要某种产品,只需向工厂请求即可。消费者无须修改就可以接纳新产品。缺点是当产品修... 阅读全文

posted @ 2011-01-19 12:36 几百人有爱 阅读(116) 评论(0) 推荐(0)

常用正则表达式
摘要:验证数字的正则表达式集 验证数字:^[0-9]*$验证n位的数字:^/d{n}$验证至少n位数字:^/d{n,}$验证m-n位的数字:^/d{m,n}$验证零和非零开头的数字:^(0|[1-9][0-9]*)$验证有两位小数的正实数:^[0-9]+(.[0-9]{2})?$验证有1-3位小数的正实数:^[0-9]+(.[0-9]{1,3})?$验证非零的正整数:^/+?[1-9][0-9]*$验证非零的负整数:^/-[1-9][0-9]*$验证非负整数(正整数 + 0) ^/d+$验证非正整数(负整数 + 0) ^((-/d+)|(0+))$验证长度为3的字符:^.{3}$验证由26个英文.. 阅读全文

posted @ 2011-01-06 17:33 几百人有爱 阅读(147) 评论(0) 推荐(0)