随笔分类 -  C++

摘要:了解位操作符之前,先看下ASCII码表。 参考资料 感受异或的神奇 阅读全文
posted @ 2017-11-02 21:01 Sawyer Ford 阅读(145) 评论(0) 推荐(0)
摘要:先上一张镇楼图 再来一个demo PS: http://www.cplusplus.com/reference/cstdio/sscanf/ 阅读全文
posted @ 2017-08-07 16:32 Sawyer Ford 阅读(186) 评论(0) 推荐(0)
摘要:原子操作类似数据库中的事务,操作中的所有指令要么全部执行,要么全部不执行。 以自增操作为例,a++对应三个CPU指令: 在单核多线程程序中,如果对一个变量的自增操作是原子的,那么就没有必要在自增操作外围加锁了。 在多核多线程程序中,由于自增操作可以在多个CPU中同步执行,即使自增操作是原子的,我们也 阅读全文
posted @ 2017-07-28 14:59 Sawyer Ford 阅读(190) 评论(0) 推荐(0)
摘要:整理一波c读写文件的API。 fopen In order to open a file as a binary file, a "b"character has to be included in the mode string. fread Reads an array of count ele 阅读全文
posted @ 2017-07-27 11:55 Sawyer Ford 阅读(190) 评论(0) 推荐(0)
摘要:c++的并发涉及到这么几个东西: std::thread std::mutex std::lock_guard std::lock 参考资料: http://en.cppreference.com/w/cpp/thread/lock C++11 并发指南三(std::mutex 详解) 阅读全文
posted @ 2017-07-13 19:38 Sawyer Ford 阅读(178) 评论(0) 推荐(0)
摘要:C++17都出来了,是时候整理一波C++11旧特性了。 参考资料: C++开发者都应该使用的10个C++11特性 http://zh.cppreference.com/w/cpp/memory/shared_ptr http://zh.cppreference.com/w/cpp/memory/we 阅读全文
posted @ 2017-07-13 10:02 Sawyer Ford 阅读(175) 评论(0) 推荐(0)
摘要:总是记不住内存相关函数的API,特此记录。 1. malloc Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.The content of the newly 阅读全文
posted @ 2017-05-24 09:00 Sawyer Ford 阅读(199) 评论(0) 推荐(0)
摘要:参考资料: [内存管理]智能指针的好帮手weak_ptr 阅读全文
posted @ 2017-04-03 09:37 Sawyer Ford 阅读(232) 评论(0) 推荐(0)
摘要:traits编程技法利用了“内嵌型别”的编程技巧与编译器的template参数推导功能。 下面主要看看利用traits编程技法实现的迭代器萃取机制。 5种迭代器类型定义: std::iterator的定义 如果想和STL协同工作,自行定义的迭代器必须定义iterator_category、value 阅读全文
posted @ 2015-08-04 10:00 Sawyer Ford 阅读(239) 评论(0) 推荐(0)
摘要:STL以泛型思维为基础,提供了6大组件:容器(containers)、算法(algorithms)、迭代器(iterators)、仿函数(functors)、适配器(adapters)、分配器(allocators)。 容器: vector、list、deque、set、map等,用来存放数据。从实 阅读全文
posted @ 2015-08-04 09:22 Sawyer Ford 阅读(315) 评论(0) 推荐(0)
摘要:《Effective C++》在资源管理一节提到了智能指针,智能指针中最著名的当属auto_ptr和shared_ptr。本文主要研究两者的实现。auto_ptr的实现:template class auto_ptr{private: T *ptr;public: explicit ... 阅读全文
posted @ 2015-06-03 16:37 Sawyer Ford 阅读(356) 评论(0) 推荐(0)
摘要:类中3个重要的成员函数,标准形式如下:class A{public: A(); A(const A&); A& operator=(const A&); ~A();}; 以后会补充 阅读全文
posted @ 2015-06-01 09:51 Sawyer Ford 阅读(165) 评论(0) 推荐(0)
摘要:本文结论: const对象、指向const对象的指针或引用只能用于调用其const成员函数。实例说明:class A{public: void mf1(){ cout<<"Function Call"<<endl; } void mf2() const{ cout<<"const F... 阅读全文
posted @ 2015-03-04 22:27 Sawyer Ford 阅读(143) 评论(0) 推荐(0)
摘要:最近在接触软件注册模块,需要获取硬盘序列号来生成注册码。 硬盘序列号,英文名:Hard Disk Serial Number,该号是硬盘厂家为区别产品而设置的,是唯一的。网上搜索一下,发现获取硬盘序列号的代码遍地都是,但很多是错误的。典型代表就是使用GetVolumeInformation函数获取序 阅读全文
posted @ 2015-01-12 18:58 Sawyer Ford 阅读(8653) 评论(1) 推荐(1)
摘要:1. string to int && int to string 2. 整数1转换成字符串"001" 3. strncpy 参考资料: https://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string- 阅读全文
posted @ 2014-11-10 11:36 Sawyer Ford 阅读(209) 评论(0) 推荐(0)
摘要:如何获取某一文件夹下所有文件名,是一个很有意思的问题。网上代码很多,找了个简单的,特此收录。 原文链接如下:http://blog.sina.com.cn/s/blog_670d5f330100lqnm.html 阅读全文
posted @ 2014-11-07 21:34 Sawyer Ford 阅读(1718) 评论(0) 推荐(0)