自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

疾风知劲草

冲上云霄

  • 博客(11)
  • 收藏
  • 关注

原创 enable_shared_from_this小例子

enable_shared_from_this是针对类中数据传出shared_ptr出现多次析构而设计的class Test //这种情况会析构两次,有段错误{public: ~Test() { cout << "析构了!" << endl; } shared_ptr<Test> GetThis() { re...

2018-07-31 19:01:41 213 1

原创 std里find和find_if

find和find_if都用在容器里寻找特定值,find用法比较单一,没法使用匿名函数等谓词操作,这样的情况不妨用find_if试试。这里同时复习一下,匿名函数里面[&]或者[=]都表示可以任意捕捉外部数据,但是[&]把捕捉到的数据用引用传入,因此,一般的情况推荐用这种。

2017-08-08 17:57:28 1473

原创 string和char*互转

char*转string:char* a="hello";string s=string(a,strlen(a));或者直接转 s=a;string转char*:string s="hello";char* p=s.data();或者char* p=s.c_str();

2017-08-02 18:44:52 308

原创 c++11自带thread完成一个双线程交替买票程序

c++11果然非常强大,没想到自带了thread类,这样在windows上就省去了很多不必要的麻烦。下面是一个简单的交替卖票的demo,每个线程里面有加入了互斥锁#include "iostream"#include "thread"#include "vector"#include "string"#include "mutex"#include "windows.h"usi

2017-08-02 16:11:21 802

原创 swap()使用情况

很多时候,一个容器变量需要多次使用,而在重复使用过程中可能没有覆盖掉上次的数据。    基于这种情况,推荐使用swap,比如容器的赋值时可以直接swap(),内存互换,也省掉了一次拷贝的过程。    同时,对于vector这样的容器push_back,可以先push_back一个空的变量,然后用back()来swap()想push的数据

2017-07-26 11:28:48 435

原创 指向vector的指针

在公司用到一个奇怪的例子,就是vector里存放指针,指针指向一个vector,自己写了一个小demo,例子如下:#include "iostream"#include "algorithm"#include "vector"#include "memory"#include "ctime"using namespace std;struct Ipvseg{ Ipvseg(int

2017-07-20 14:55:26 6348 1

原创 一个有意思的关于函数指针用在vector里的模型

根据实习公司项目的需要,我对一小部分代码进行了重构,本来以为不算什么,但在今天的调试过程中一路遇上了很多坑,且把这些记下来,录了一个代码的简单模型:  ban.h#include "iostream"#include "vector"#include "stdlib.h"#include "map"using namespace std;class ban{

2017-07-14 14:08:00 397

原创 leetcode542

Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:0 0 00 1 00

2017-04-27 11:02:15 345

原创 一个很值得思考的问题,求解决!

今天看了一个博客的单例模式,将唯一实体设为const static后,同时把构造函数私有,在类外对实体直接调用构造函数进行了初始化,简化后为class single {private: const static single* m_instance; single() {}};const single* single::m_instance = new single;不理解为什么设

2017-04-24 11:21:34 986

原创 leetcode120

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [

2017-04-22 16:03:44 355

原创 static_assert和assert的基本区别(可能不全)

assert是从C语言中继承过来的的断言方式,属于运行期断言,不具有强制性,也无法提前到编译器,这样在程序发型的时候需要关掉,以免造成不必要的浪费。static_assert属于对assert的不足进行弥补,当编译阶段就可以进行静态的检测

2017-04-14 15:34:53 3037

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除