![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++学习
文章平均质量分 67
zzucaicai
科学院南路6号
展开
-
istream 重复读文件
bool KmerTable::read(std::istream& stream) { while(stream.read()){}stream.clear();stream.seekg(0, std::ios::beg);继续读}读文件结束后,istream badbit被设置,需要clear成goodbit后再移动stream到文件头原创 2015-07-27 17:16:42 · 297 阅读 · 0 评论 -
boost bind及多线程
之前项目中用到学习了一下,今天总结总结bind生成一个仿函数,可以配接任意函数(裸函数,类成员函数,静态成员函数)指定参数传递方式个数。在需要仿函数的地方(accumulate,for_each等)超级好用原创 2016-03-14 09:08:59 · 1687 阅读 · 0 评论 -
boost mutex lock学习及测试
boost真是博大精深呀这次学习了一下几本的锁和信号量。其中包含:mutex recursive_mutex lock unique_lock basic_lockable_adpator timed_lockable_adpator,其他的adpator应该也都一样,例如(shared_lockable_adaptor等)参看:http://www.boost.org/doc/lib原创 2016-03-11 10:16:13 · 886 阅读 · 0 评论 -
boost 字符串常用函数初窥
boost/algoththm/string.hpp 中常用函数测试。包含:split cast_conv erase find predicate replace trim regex等#include #include #include #include #include #include #include #include int main(int argc,原创 2016-03-07 17:07:47 · 514 阅读 · 0 评论 -
c++11 学习及测试(虚继承 虚函数时类的内存分布)
下面是一个写的超级好的blog,详细解释了类的内存分布以及虚函数的调用方式。。膜拜之。。虚函数虚继承及类的内存分布下面是我写的一个测试代码。。关于内存分布参见上面链接代码中主要测试了类的内存分布不同时,指针引用强转可能出现的情况,发现现在的编译器真是做的好。指针和引用在类继承体系中强转,对应的地址也会改变以指向对象中对应要转向类型部分的起始地址,只有在先强转成void*再转时才原创 2016-03-25 15:52:09 · 473 阅读 · 0 评论 -
c++ 如何把this指针传入成员函数 像全局函数一样调用成员函数
测试这个功能的初衷是测试boost里面的bindboost::bind((&A::sum), &a, _1, _2)上面的代码是我boost bind及多线程这篇博客里面的一行代码。我就像boost是怎么做到这样调用一个类的成员函数的。其实成员函数和全局函数无非就是差一个this指针参数。给传进去不久也可以调用了。然而并没有那么简单。看了boost的源码表示太长了。没怎么看懂然后就原创 2016-05-06 17:24:31 · 2957 阅读 · 0 评论 -
使用boost graph library计算图中点和边的betweenness
项目中用到的东西,betweenness是社交网络里的概念。基于的思想是betweenness高的点和边在网络中更重要。betweenness具体定义见这里搜了一下发现boost已经有实现,但是用起来也真是费了牛劲。模版类一不小心就写错,而且编译出错信息完全看不出来什么。搜了文档和例子才算写好了。。下面是一个星状图的例子:input:0 1 1 // an edge from 0原创 2016-06-16 15:07:37 · 1653 阅读 · 0 评论 -
使用boost实现python调用c++
使用boost.python实现python调用c++代码编写c++代码后,编译成动态链接库,然后python可以直接调用参考http://www.boost.org/doc/libs/1_61_0/libs/python/doc/html/index.html代码中实现了python参数,到c++参数的转化,可以把一个python的可迭代对象转化成c++中的list map vect原创 2016-07-08 16:06:33 · 1386 阅读 · 0 评论 -
vector配合多线程的bug
今日加利福尼亚大学同学来访问,写的程序core了,帮忙调试好半天。。纪录一下奇葩的bug。起始bug的原因挺容易想到的,而且也是写代码的时候应该注意的地方。应为vector内存动态增长的原因,vector中的元素的指针和引用都是不可靠的。当然这一点在单线程时基本没有问题。但是多线程就跪了。多线程传给线程函数一个vector中元素的指针,而主线程会改这个vector,导致线程函数需要用vec原创 2016-08-10 14:40:14 · 2569 阅读 · 0 评论 -
c++11 学习及测试(shared_ptr, unique_ptr, allocator, function)
只能指针shared_ptr、unique_ptr,构造及使用,make_sheard,可以构造sheard_ptr,但是并没有make_unique。。#include #include #include using namespace std;class SharedStrings {public: SharedStrings(): _strsPtr(make_shar原创 2016-03-23 22:38:34 · 708 阅读 · 0 评论 -
c++11 学习及测试(constexpr,using,default构造函数,lamada表达式)
constexpr 常量表达式,编译器直接推断值。using代替typedef(using可以指定模版类型别名)#include #include using namespace std;constexpr int new_size(int x) {return 42*x;}templateclass A { T _a;public: A(T a): _a(a)原创 2016-03-22 11:19:40 · 790 阅读 · 0 评论 -
c++11 学习及测试(auto,decltype,range for...)
花费一星期学校了一下c++11,重看c++ prime感觉第五版的例子比第四版好了很多呀。而且还加入了设计模式之类的东西。也或许是之前看的时候还不知道什么是设计模式T_T。写了一写测试代码,记录一下以备后用。 使用auto和decltype自动推倒类型:注意事项见源码中注释#include using namespace std;int f() { return 10原创 2016-03-21 18:44:17 · 393 阅读 · 0 评论 -
gdb调试
gdb ./programset argsl listr runc continue to next break pointb num/function name set break pointn next lines next step, go into functionfinish jump out a functionp printinfo b vie原创 2015-08-05 08:50:41 · 259 阅读 · 0 评论 -
for_each可能导致的数据丢失
调试了一下午的begug,太坑爹了。。多亏了gdb如果一个类里面的有存储数据,还重载()操作符做为仿函数,重载的函数向类里存数据。这样类似for_each(a.begin(), a.end(), stor); 因为for_each中stor是值传递,会导致先调用copy构造函数,这样数据就被存储在了新构造的类里,并没有存在实际参数stor中,导致数据丢失。。可以使用std::for_eac原创 2015-08-05 08:26:30 · 804 阅读 · 0 评论 -
c++ 线程池
项目要多线程化,写生产者消费者模型。想到很久以前看过线程池, 所以就写写熟练一下参考 http://blog.csdn.net/kankan231/article/details/24499947/***********************************任务接口,抽象类 task.h***************************************/原创 2015-11-04 11:19:47 · 363 阅读 · 0 评论 -
more effective c++(cast pleacementNew explicit)
之前看的书写的代码都没有保存,以至现在都找不到了。还是保存一下吧。。以后还可以拿来看前四章,类型转化 指针操作多态数组 隐士类型转化。代码中稍许注释,仅限自己看懂。。。#include using namespace std;class A { int a;public: A(int aa = 0):a(aa) { } void updateAndSho原创 2015-10-30 09:35:17 · 304 阅读 · 0 评论 -
more effective c++(临时对象的返回值优化)
#include using namespace std;class A {public: const A operator + (const A & x) { // 返回const对象 A re(_a + x._a); cout << "operator + " << endl; return re; } A(int原创 2015-12-18 23:09:31 · 378 阅读 · 0 评论 -
more effinctive c++(operator+=)
#include using namespace std;class A{public: A(int a=0): _a(a) { cout << "construct" << endl; } A & operator += (const A & x) { cout << "operator +=" << endl; _原创 2015-12-20 22:47:14 · 351 阅读 · 0 评论 -
c++11 学习及测试(emplace_back实现方式 数学分布 正则表达式)
可变长度参数列表,参数原始类型转发(emplace_back实现方式)#include #include #include #include using namespace std;templateT make(T, Args&& ... rest) { //模版参数列表,右值引用调用构造函数 cout << sizeof...(rest)原创 2016-03-31 10:42:05 · 824 阅读 · 0 评论 -
more efficitive c++(prefix postfix and operator new)
知识点:1,prefix:increment and fetch postfix:fetch and increment2,前值和后置的标准写法,见代码(返回值!!!)3,new分为两步 一,调用operator new分配空间 二,调用pleasement new构造对象。operator new要用operator delete释放#include #includ原创 2015-11-04 09:16:52 · 560 阅读 · 0 评论 -
c++中构造函数调用构造函数
c++中构造函数完成的工作分两步:1 分配空间 2 初始化空间构造函数调用构造函数。class A {public: A() { A(0) // new(this)A(0) 可用办法,使用pleacement new 在串入的指针this位置构造对象 } A(int a) { _a = a; }private: i原创 2016-05-24 10:44:22 · 631 阅读 · 0 评论