C++ boost库
boost案例集
莫忘输赢
书读百遍,其义自见...
展开
-
Boost开发-学习笔记-内存管理-解析boost库中的智能指针
一、smart_ptr库概述计算机系统中资源分很多种,内存是我们最常用的,内存使用需要申请和及时的释放。1、RALL机制概述为了管理内存等资源,C++程序员通常采用RALL(资源获取及初始化)机制,在类中构造函数中申请内存,在析构函数中释放内存。当对象是在栈上创建的,那么RALL机制会正常工作,离开作用域的时候会自动释放资源。如果使用new操作符进行创建,析构函数不能释放资源,需要使用...原创 2019-09-24 09:38:05 · 347 阅读 · 0 评论 -
Boost库-内存管理-智能指针-scoped_ptr
#include<iostream>#include<string>#include<boost\scoped_ptr.hpp>#include<boost\assign.hpp>int main(int argc, char** argv){ boost::scoped_ptr<std::string> sp(new ...原创 2020-03-01 09:44:53 · 121 阅读 · 0 评论 -
Boost库-signals2-signal/slot
#include<iostream>#include<boost\signals2.hpp>void SignalSlots1(){ std::cout << "SignalSlots1 Called"<<std::endl;}void SignalSlots2(){ std::cout << "SignalSlo...原创 2020-02-28 07:36:48 · 412 阅读 · 0 评论 -
Boost库-asio
#define BOOST_ASIO_DISABLE_STD_CHRONO#include <iostream>#include <boost\asio.hpp>#include <boost\chrono.hpp>#include <boost\asio\steady_timer.hpp>#include "print.hpp"i...原创 2020-02-27 09:37:28 · 215 阅读 · 0 评论 -
Boost学习-学习笔记-windows开发环境搭建
一、获取boost库,由于有些时候下的比较慢,当然获取最新版本的话可以去官网(进官网:http://www.boost.org),我采用的boost库版本号为1.69,提供百度云下载链接:链接:https://pan.baidu.com/s/11DKaT8BjqNN-kqAVqzLRYw提取码:1ny2复制这段内容后打开百度网盘手机App,操作更方便哦二、转载因为boo...原创 2019-09-17 13:05:19 · 321 阅读 · 0 评论 -
Boost库-integer-static_lcm/static_gcd(最大公因子及最小公倍数)
#include<iostream>#include <boost/integer/common_factor_ct.hpp>int main(int argc, char** argv){ std::cout <<"3和5的最小公倍数数为:"<< boost::integer::static_lcm<5, 3>::va...原创 2020-03-03 22:40:09 · 333 阅读 · 0 评论 -
Boost库-signals2-signal/slot-应用观察者模式(闹铃-护士-孩子)
#define _SCL_SECURE_NO_WARNINGS#include<iostream>#include<boost\signals2.hpp>#include<boost\random.hpp>#include<boost\bind.hpp>typedef boost::variate_generator<boos...原创 2020-02-29 17:46:50 · 245 阅读 · 0 评论 -
Boost库-C++基础知识-数组大小
#include<iostream>int main(int argc, char** argv){ int a[5] = { 0 }; std::cout << "sizeof(a) == "<< sizeof(a) << std::endl; return 0;}原创 2020-03-03 23:20:42 · 234 阅读 · 0 评论 -
Boost库-ref-reference_wrapper
#include<boost\ref.hpp>#include<boost\assert.hpp>#include<iostream>/*ref很小定义了一个很小,很简单的引用类型包装器命名为reference_wrappertemplate<class T>class reference_wrapper{public://构造...原创 2020-02-27 08:30:36 · 308 阅读 · 0 评论 -
Boost库-asio-tcp同步客户端及服务端
#include<boost\asio.hpp>#include<iostream>#include<vector>#include<vld.h>int main(int argc, char** argv){ try { typedef boost::asio::ip::tcp::endpoint endpoint_type;...原创 2020-02-27 09:40:32 · 852 阅读 · 0 评论 -
Boost库-内存管理-智能指针-shared_ptr更深层次使用
#include<iostream>#include<boost\shared_ptr.hpp>class TestSharedPtr{private: boost::shared_ptr<int> p_;public: TestSharedPtr(boost::shared_ptr<int> p):p_(p){ } void ...原创 2020-03-01 11:24:38 · 128 阅读 · 0 评论 -
Boost库-signals2-slot/signal-分组
#define _SCL_SECURE_NO_WARNINGS#include<iostream>#include<boost\signals2.hpp>//函数对象template<int N>class slot{public: void operator()() { std::cout << "slot" <...原创 2020-02-28 08:41:37 · 230 阅读 · 0 评论 -
Boost库-random-[0,100]随机数自生成
#include <iostream>#include<boost\random.hpp>//typedef boost::variate_generator<boost::rand48, boost::uniform_int<>> bool_rand;bool_rand g_rand(boost::rand48(time(0)), bo...原创 2020-02-29 17:09:39 · 437 阅读 · 0 评论 -
Boost库-signals2-signal/slot-返回值合成器
#define _SCL_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<boost\signals2.hpp>//函数对象template<int N>class slot{public: int operator()(int x) { std...原创 2020-02-28 09:22:08 · 295 阅读 · 0 评论 -
Boost库-signals2-signal/slot-信号自动断开槽接口
#define _SCL_SECURE_NO_WARNINGS#include<iostream>#include<boost\signals2.hpp>#include<boost\make_shared.hpp>//函数对象template<int N>class slot{public: //重载()运算符 void...原创 2020-02-28 15:27:54 · 485 阅读 · 0 评论 -
Boost开发-学习笔记-日历
一、环境配置二、输入代码/*data_timer*/#include<boost\date_time\gregorian\gregorian.hpp>#include<iostream>//处理时间的组件#include <boost\date_time\posix_time\posix_time.hpp>using nam...原创 2019-09-17 22:21:07 · 135 阅读 · 0 评论 -
Boost库-signals2-signal/slot-返回值
#define _SCL_SECURE_NO_WARNINGS#include<iostream>#include<boost\signals2.hpp>//函数对象template<int N>class slot{public: int operator()(int x) { std::cout << "slot"...原创 2020-02-28 08:58:52 · 388 阅读 · 0 评论 -
Boost库-array
#include<iostream>#include<boost\array.hpp>#include<boost\assert.hpp>int main(int argc, char** argv){ //数组大小为10 boost::array<int, 10> arrayList = { 0 }; for (int i...原创 2020-02-29 22:56:15 · 122 阅读 · 0 评论 -
Boost-signals2-signal/slot-disconnect
#define _SCL_SECURE_NO_WARNINGS#include<iostream>#include<boost\signals2.hpp>//函数对象template<int N>class slot{public: //重载()运算符 void operator()() { std::cout << ...原创 2020-02-28 09:53:30 · 415 阅读 · 0 评论 -
Boost库-内存管理-智能指针-weak_ptr
#include<iostream>#include<boost\weak_ptr.hpp>#include<boost\shared_array.hpp>int main(int argc, char** argv){ boost::shared_ptr<int> sp0(new int(100)); std::cout &l...原创 2020-03-01 15:17:33 · 127 阅读 · 0 评论 -
Boost开发-学习笔记-计时器(秒)
一、配置环境二、 插入代码段/*方便的秒表*/#include<boost\timer.hpp>#include<iostream>using namespace std;using namespace boost;int main(int argc, char **argv){ timer t; cout << "max time...原创 2019-09-17 21:04:22 · 173 阅读 · 0 评论 -
Boost库-function
#include<iostream>#include<vector>#include<boost\function.hpp>#include<boost\assert.hpp>#include<boost\bind.hpp>#include<boost\ref.hpp>int Add(int a, int b...原创 2020-02-27 16:14:25 · 139 阅读 · 0 评论 -
Boost库-C++基础-关于含有静态常量成员变量的类的大小计算
#include<iostream>class CObj{public: int x; static const int y = 5;};int main(int argc, char** argv){ std::cout <<"sizeof(CObj) == " <<sizeof(CObj) << std::endl; r...原创 2020-03-03 23:48:48 · 243 阅读 · 0 评论 -
Boost库-内存管理-智能指针-shared_ptr
#include<iostream>#include<vld.h>#include<boost\shared_ptr.hpp>#include<boost\assert.hpp>void testSharedPtr(){ boost::shared_ptr<int> sp0(new int(10)); //指针...原创 2020-03-01 10:43:53 · 133 阅读 · 0 评论 -
Boost库-pool库-完全解析
一、boost库中pool库-类图概要1、概览2、概述2.1、struct default_user_allocator_new_delete 与struct default_user_allocator_malloc_freestruct default_user_allocator_new_delete中定义两个静态函数用于内存的分配与释放,分别为static c...原创 2020-03-04 23:37:23 · 1241 阅读 · 0 评论 -
Boost库-asio-异步客户端与服务端
客户端类定义文件 ClientAsync.hpp#ifndef __Client_Async_hpp__#define __Client_Async_hpp__#include<iostream>#include<boost\asio.hpp>#include<boost\bind.hpp>class ClientAsync{ type...原创 2020-02-27 09:44:54 · 889 阅读 · 0 评论