上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 24 下一页
摘要: 功能:查找第二个字符串是否存在第一个字符串中。输入:字符串1,字符串2返回值:成功返回str1中的位置,失败返回NULL#include using namespace std;char *_strstr(const char *str1,const char *str2){ int n; if (*str2) { while(*str1) { for (n = 0;*(str1 + n) == *(str2 + n);n++) { if (!*(str2 +n +1)) { return (char*)str1; } } str1++; } ... 阅读全文
posted @ 2013-08-20 23:44 l851654152 阅读(316) 评论(0) 推荐(0) 编辑
摘要: STL处理内存主要是使用五个全局函数construct,deconstruct,construct实现:templatevoid construct(T1* p,const T2 value){new (p) T1(value);}uninitialized_fill,uninitializad_fill_n,unintialized_copy,通过trait特性,如果T是内置类型使用直接“=”,如果是自定义类型则使用construct一个个拷贝。 阅读全文
posted @ 2013-08-19 23:47 l851654152 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 在前面很多随笔里都有提到new对象是先分配内存然后初始化对象,主要是对operator new和placement new的使用在SGI STL中内存的分配和初始化是分开的,分配内存是使用类模板,模板参数是非类型模板参数,不过完全没有派上用场。当内存大于128byte时使用第一级空间配置器,当内存小于128byte时使用第二级空间配置器。对象的构造和析构是使用全局对象。 阅读全文
posted @ 2013-08-18 23:09 l851654152 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 1.保存I/O流下面这段代码cout会失效,原因是cout重定向之后失效。#include #include using namespace std;//using namespace boost;int main(){ string filename("c:/test.txt"); cout << "log start" <<endl; if (!filename.empty()) { ofstream fs(filename.c_str()); cout.rdbuf(fs.rdbuf()); } cout << & 阅读全文
posted @ 2013-08-17 22:54 l851654152 阅读(355) 评论(0) 推荐(0) 编辑
摘要: shared_pt很强大的功能,但是也有缺陷1.重复析构2.循环使用,内存泄漏。 阅读全文
posted @ 2013-08-17 13:40 l851654152 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 1.trait特性可以和特化或者偏特化结合。2.trait可以和类型转换结合。 阅读全文
posted @ 2013-08-17 13:39 l851654152 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 1.random随机数产生,需要种子,下面以时间为种子示例:#include #include #include #include #include using namespace std;using namespace boost;int main(){ mt19937 rng(time(0)); for (int i = 0;i < 100;++i) { cout << rng() << "-" <<endl; } return 0;} 阅读全文
posted @ 2013-08-17 12:24 l851654152 阅读(278) 评论(0) 推荐(0) 编辑
摘要: STL里的算法已经很好了,在boost里有几个小的算法1.BOOST_FOREACH使用方法,定义一个容器里内部类型数据,容器作为参数传递。#include #include #include #include #include using namespace std;using namespace boost::assign;int main(){ vector v = list_of(1)(2)(3)(4)(5); BOOST_FOREACH(int x,v) { cout #include #include #include #include #include #include us.. 阅读全文
posted @ 2013-08-17 11:29 l851654152 阅读(2016) 评论(0) 推荐(0) 编辑
摘要: 1.静态数组array,boost对静态数组进行了封装,使用和普通数组一样的初始化式进行初始化。#include #include using namespace std;using namespace boost;int main(){ array ar; ar.back() = 10; array ar1 = {"tiger","dog","cat"}; return 0;}2.dynamic_bitset可以自由扩充二进制位的位数,可以自由进行位操作,还有一堆方便操作判断的函数。#include #include using n 阅读全文
posted @ 2013-08-17 00:51 l851654152 阅读(3434) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 24 下一页