
C++11
Car12
嵌入式开发,爱好者
展开
-
C++ ifstream 读取文件大小和读取所有内容
ifstream ifs(file_name, std::ios::binary|std::ios::in);if (ifs.is_open()){ ifs.seekg(0,std::ios::end); int len = ifs.tellg(); ifs.seekg(0,std::ios::beg); char *buff = new char[len]; ifs.read(buff , len); delete []buff;}.原创 2020-08-18 16:01:00 · 9229 阅读 · 0 评论 -
std::move()源码分析
https://segmentfault.com/a/1190000020744971?utm_source=tag-newestC++11 引入右值和移动语义,其中std::move()是不可或缺的。现在我们才看看std::move()是这么实现的。remove_reference在分析std::move()之前,先看看remove_reference,下面是remove_re...转载 2020-04-19 00:32:31 · 344 阅读 · 0 评论 -
C++ 深拷贝和浅拷贝std::move移动构造函数,移动赋值函数
一个class如果包含了指针成员的话那就必须实现构造函数, 析构函数, 拷贝构造函数, 移动构造函数, 移动赋值函数上述缺少一个都会造成内存泄漏;=delete =default 关键字一般只会用在上述几个函数,普通函数几乎不用,一个class 对象对容器的操作在没有实现移动构造函数的情况之下,就会调用拷贝构造函数实现push_back(),实现移动构造函数的情况之下,就会...原创 2020-04-18 20:09:15 · 2728 阅读 · 1 评论 -
EssentialC++
指针既可以操作指针所指向的内存地址,亦可以操作指针所指向的值;文件打开失败判断:ofstream ifstream 打开失败对象为假,打开成功为真if(file){}ifstream 每次读取都是一行;如果以追加的方式使用fstream (ios_base::in | ios_base::app)打开文件,文件的位置是末尾,函数入口每次都必须对传入参数的合理性判断;函数在有返...原创 2020-03-11 15:14:17 · 643 阅读 · 0 评论 -
C++ 关于复制、移动构造函数和移动、复制 赋值运算符的重载问题;
可以取地址的是左值,左值在内存中不在寄存器;int a; char b; a,b 都是左值;去不了地址的都是右值,右值不在内村中实在寄存器内部; int c= a+b ;"a+b" 就是一个右值move()可以实现将一个左值转换为右值的功能// std::swap#include <iostream>#include <vector> // std::v...原创 2020-03-08 21:30:57 · 1003 阅读 · 0 评论 -
JsonCpp测试代码使用新API
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include <fstream>#include <string>#include "json.h"#include <memory>#include <...原创 2020-01-09 15:27:32 · 576 阅读 · 0 评论 -
vs2013 可用的json库
/* Copyright (c) 2009 Dave Gamble Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in th...原创 2020-01-09 11:49:47 · 545 阅读 · 0 评论 -
VS2013 生成sqlite3动态连接库
一,生成sqlite3动态连接库1,去sqlite官网上下载最近的sqlite源码包,解压后得到四个文件:shell.c,sqlite3.c,sqlite3.h,sqlite3ext.h此处还需要sqlite3.def文件,它在sqlite官方生成的dll包中,下载下来,解压即可。其中,shell.c文件是做来生成exe可执行文件用的。2,打开vs2008 新建sqlite3的非mfc的D...转载 2019-05-17 21:46:40 · 250 阅读 · 0 评论 -
sqlite3学习笔记-方法介绍和测试代码
创建数据库 :sqlite3 test.db查看数据数据 : .databases创建表 :create table student (id integer primary key autoincrement,name txt,age int, birthday txt)查看表 :.tables删除表:drop table test.menber===================...原创 2019-05-19 19:23:18 · 953 阅读 · 0 评论 -
Windows核心编程之线程池在回调函数和定时调用(定时器)
#include"stdafx.h"#include<windows.h> #include<iostream>using namespace std;void CALLBACK Work(PTP_CALLBACK_INSTANCE instance,PVOID context,PTP_WORK work){ int *p=static_cast<int...原创 2018-05-14 21:46:27 · 554 阅读 · 0 评论 -
vs2010 导出创建dll 导入使用dll 导出有命名空间的类 函数 外部函数
2、#include "targetver.h"// dlltest.cpp : 定义 DLL 应用程序的导出函数。//#include "stdafx.h"#include "stdafx.h"#include "targetver.h"//#include <iostream>//using namespace std;int Add(int plus1, in...原创 2018-03-29 10:10:34 · 1521 阅读 · 0 评论 -
lambda函数
格式:[capture] (parameters) mutable ->return-type {statement}[capture]:捕捉列表(parameters) : 参数列表,不传参数可以连括号一起省略mutable :修饰符,默认情况下lambda函数是一个const 函数,反正加上该修饰符时取消其常量行,此时必须加上参数列表-> return-ty原创 2016-05-08 09:02:40 · 485 阅读 · 0 评论 -
C++11六大函数(构造函数,移动构造函数,移动赋值操作符,复制构造函数,赋值操作符,析构函数)
转载自:http://blog.youkuaiyun.com/jofranks/article/details/17438955版权声明:本文为博主原创文章,未经博主允许不得转载。在C++中,有三大函数复制控制(复制构造函数,赋值操作符,析构函数),而在C++11中,加入了移动构造函数,移动赋值操作符。我就斗胆将他们命名为六大函数好了。一、构造函数c转载 2016-05-07 18:38:34 · 555 阅读 · 0 评论 -
委派构造函数
1,可以形成链状的委托构造函数,但是不可以形成委托环:class weipai2{private: string name; int sex; weipai2(string name,int sex):name(name),sex(sex){}public: weipai2(string name):weipai2(name,1){} weipai2(原创 2016-05-07 16:47:18 · 355 阅读 · 0 评论 -
继承构造函数
#include using namespace std;class base{private: int i;public : base(int i):i(i){} void set_value(int i) { this->i = i; } virtual int get() { return i原创 2016-05-07 12:27:34 · 339 阅读 · 0 评论