![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++应用
文章平均质量分 72
智渝
生无路而勤为径
展开
-
_MSC_VER值对应的Visual Studio版本
微软官网链接:Predefined macros截至目前[2019-11-28]:Visual Studio version_MSC_VERVisual Studio 6.01200Visual Studio .NET 2002 (7.0)1300Visual Studio .NET 2003 (7.1)1310Visual Studio 2005 ...原创 2019-11-28 23:04:51 · 3958 阅读 · 1 评论 -
C/C++预定义编译宏
Pre-defined C/C++ Compiler Macroshttps://sourceforge.net/p/predef/wiki/Home/The macros are found here:Standards Compilers Libraries Operating systems ArchitecturesGeneral guidelines are ...转载 2019-10-26 21:56:45 · 2693 阅读 · 0 评论 -
C++实现strcpy,memcpy
// 实现strcpy// 为什么返回char *? 为了实现链式表达式,如:int len = strlen(strcpy(dest, src));char *strcpy(char *dest, const char *src){ assert(dest && src); char *str = dest; while ((*dest++ = *src++) !=...原创 2019-06-23 19:45:40 · 567 阅读 · 0 评论 -
C++求容器中的最小最大值
// Visual Studio 2015编译通过// 以std::vector容器为例#include <iostream>#include <stdlib.h>#include <algorithm> // std::minmax_element#include <vector> // std::vectorint mai...原创 2019-05-29 16:42:28 · 3386 阅读 · 0 评论 -
c++ while(a小于b小于c)是怎么回事
int a = 1, b=2, c = 3;while (a < b < c)是怎么回事呢?其实它相当于while((a < b) < c),而a < b其实是个bool值,要么为true(1),要么为flase(0),再将这个bool结果与c比较, 所以可以理解为:while (1 < c) 或者while (0 < c)。...原创 2019-05-16 12:53:39 · 5359 阅读 · 0 评论 -
C++ 颜色RGB值转换为16进制
#include <sstream>/** * Transform RGB value to hex. */ std::string rgb2hex(int r, int g, int b, bool with_head = false);std::string rgb2hex(int r, int g, int b, bool with_head){ std::s...原创 2019-04-08 15:45:52 · 3676 阅读 · 0 评论 -
C++矩阵模板类的实现
/***************************************************************** Matrix template class.**** By shaoguang @ 2019-04-01.***************************************************************/#ifndef...原创 2019-04-01 17:21:01 · 1083 阅读 · 0 评论 -
C++ std::move与std::swap
在C++11中,标准库在<utility>中提供了一个有用的函数std::move,std::move并不能移动任何东西,它唯一的功能是将一个左值强制转化为右值引用,继而可以通过右值引用使用该值,以用于移动语义,确切地说,它使一个值易于移动。从实现上讲,std::move基本等同于一个类型转换:static_cast<T&&>(lvalue);std::...原创 2019-04-06 19:43:45 · 6079 阅读 · 0 评论 -
C++实现二叉查找树
/***************************************************************** BinarySearchTree.h**** BinarySearchTree template class.**** By shaoguang @ 2019-04-06.**************************************...原创 2019-04-06 18:33:09 · 241 阅读 · 0 评论 -
C++ 获取键盘事件
原文地址:https://www.runoob.com/w3cnote/c-get-keycode.html一 Windows 系统下的 vs 中可以使用 _kbhit() 函数来获取键盘事件,使用时需要加入 conio.h 头文件,例:#include <conio.h>#include <iostream> using namespace st...转载 2019-07-09 14:53:00 · 4977 阅读 · 1 评论 -
C++ 实现Variant类
Variant类借鉴于Qt的QVariant类,类似于Boost的any类。它把常用类型使用一个类包装起来,这样使用QVector等容器时,其内部就可以存储不同的数据。例如:std::vector<Variant> vec;vec.push_back(1); // 整形vec.push_back("str"); // 字符串vec.push_back(f...原创 2019-07-22 22:14:13 · 3412 阅读 · 5 评论 -
C++ string与wstring之间的相互转换
/*! * \date 2019-08-18 * \author shaoguang*/#include <string> /// std::string, std::wstring#include <clocale> /// std::setlocale#include <cstdlib> /// std::wcstombs, std::mbs...原创 2019-08-18 17:34:14 · 717 阅读 · 0 评论 -
C++将std::string和std::wstring转换为数字的函数封装(字符串转数字)
更新:(2019/11/18)利用C++17新特性,将模板简单化,通过编译期检查来判断输入参数是否有效以及确定转换函数。#ifndef STRING_TO_NUMBER_HPP#define STRING_TO_NUMBER_HPP#include <type_traits>#include <string>template<class T>...原创 2019-08-10 19:06:21 · 1296 阅读 · 0 评论 -
C++设计一个跨平台通用模板矩阵类类
github地址:https://github.com/shaoguangwu/GenericMatrix原创 2019-08-22 14:59:34 · 290 阅读 · 0 评论 -
C++获取系统环境变量
// C++标准库方式 获取系统环境变量并打印#include <iostream>#include <cstdlib> // std::getev()#include <string>#include <vector>using String = typename std::string;using StringVecto...原创 2019-08-29 22:26:39 · 640 阅读 · 0 评论 -
C++库或软件版本宏定义方式示例
#include <iostream>#include <string>#define XX_VERSION_MAJOR 1 // 主版本号#define XX_VERSION_MINOR 1 // 副版本号 #define XX_VERSION_REVISION 1 // 修正...原创 2019-09-28 13:10:28 · 1022 阅读 · 1 评论 -
C++判断大小端
bool isLittleEndian(){ union U { int i; char c; }; U u; u.i = 1; return u.c == 1;}// 或者bool isLittleEndian(){ union U { int i; ...原创 2019-10-10 11:51:06 · 956 阅读 · 1 评论 -
C++如何去除数组中的特定值(删除数组中特定的元素)?
/* * @Abstract : 去除数组中的特定值 * @Crete Date : 11/10/2018. * @Author : shaoguang. */#include <math.h> // fabs/** * @param pArray : 要去除数据的原数组。 * @param nLen : 要去除数...原创 2018-10-11 12:47:40 · 20564 阅读 · 0 评论 -
<C++>简单的学生成绩管理系统
/* 实现简单的学生成绩管理系统 */#include using namespace std;#define MAXZISE 50// 结构体的定义struct student_s{ long num; // 学号 string name; // 姓名 float score; // 分数};// 类class student_c{private: stu原创 2017-10-05 20:04:45 · 726 阅读 · 0 评论 -
<C/C++>日期和时间的使用(time相关函数大全)
·与时间相关的变量类型与时间相关的类型有四个,分别是:time_t、clock_t、size_t、tm。tm是一个结构体类型,系统定义如下:/* tm结构体 */struct tm{ int tm_sec; // 秒:0-59(允许至61) int tm_min; // 分:0-59 int tm_hour; // 时:0-23 int tm_mday原创 2017-09-28 16:43:27 · 2653 阅读 · 0 评论 -
<c++>两个特别大的数之间相乘怎么计算?
两个数特别大,相乘起来超过了long int型的范围?怎么计算?比如:要计算123456789987654321 * 987654321123456的值,怎么写程序?/* large_num_operation.cpp */#include #include using namespace std;void calc_result(string first, strin原创 2017-09-26 20:05:20 · 1687 阅读 · 0 评论 -
<c++>c++三种单例模式实现
简介 因为在设计或开发中,肯定会有这么一种情况,一个类只能有一个对象被创建,如果有多个对象的话,可能会导致状态的混乱和不一致。这种情况下,单例模式是最恰当的解决办法。它有很多种实现方式,各自的特性不相同,使用的情形也不相同。今天要实现的是常用的三种,分别是饿汉式、懒汉式和多线程式。 通过单例模式, 可以做到:1. 确保一个类只转载 2017-09-27 11:05:43 · 460 阅读 · 0 评论 -
<C/C++>指针在什么时候需要申请内存空间?
指针什么时候需要申请内存空间??1、指针所指向的地址需要存放数据的时候需要申请空间。int *q;只有地址,没有内存空间。这个地址是随机地址。(1)没有申请内存空间:int *q;*q = 1;cout错误!指针变量q没有空间,不能直接存放数据。 (2)申请内存空间:int *q = new int原创 2017-09-25 10:42:53 · 6577 阅读 · 4 评论 -
<C++>const在不同对象不同位置中的作用
一、 const与define. 两者都可以用来定义常量,但是const定义时,定义了常量的类型,所以更精确一些。#define只是简单的文本替换,除了可以定义常量外,还可以用来定义一些简单的函数,有点类似内联函数(Inline)。const和define定义的常量可以放在头文件里面。(小注:可以多次声明,但只能定义一次)二、 const与指针,引用(a)const与指针转载 2017-09-23 19:47:47 · 842 阅读 · 0 评论 -
<C++>c++程序有函数重载,能不能设置默认参数值?
答案是可以的,虽然可能出现错误。如:#include using namespace std;int arr(int x){ return x;}int arr(float x, float y=2){ return x+y;}int main(void){ int a=1, b=2.0; cout<<arr(a)<<endl; cout<<arr(b原创 2017-09-23 18:48:46 · 2140 阅读 · 0 评论 -
<C++>C++源文件包含C源文件(C++中如何使用C)
如下代码:/*C语言头文件:Max.h*/#ifndef _MAX_H_#define _MAX_H_int Max(int nA,int nB)#endif/*C语言实现文件:Max.c*/#include "Max.h"int Max(int nA,int nB){ return((nA-nB)?(nA):(nB));}/*C++语言调用文件*/#i转载 2017-08-28 09:27:55 · 1810 阅读 · 0 评论 -
<C++>15.this指针
15.this指针一、概述1、概念:this指针是隐含与每一个成员函数中的特殊指针。它指向正操作该成员函数的对象。2、this指针的产生:当对象调用成员函数时,程序先将对象的地址赋予this指针,然后调用成员函数。 二、应用举例/* this_ptr.c */#include using原创 2017-10-05 20:35:45 · 308 阅读 · 0 评论 -
C++三大特性 -- 继承
转载自:http://www.cnblogs.com/quincyhu/p/5867490.html基本概念继承: 类的继承,就是新的类从已有类那里得到已有的特性。原有的类称为基类或父类,产生的新类称为派生类或子类。基本语法派生类的声明:class 派生类名:继承方式 基类名1, 继承方式 基类名2,...,继承方式 基类名n{ 派生类成员声明;转载 2017-10-29 17:45:41 · 280 阅读 · 0 评论 -
C++三大特性 -- 封装
转载自:http://www.cnblogs.com/quincyhu/p/5867468.html什么是封装?封装: 封装可以隐藏实现细节,使得代码模块化封装是把过程和数据包围起来,对数据的访问只能通过已定义的界面。在面向对象编程上可理解为:把客观事物封装成抽象的类,并且类可以把自己的数据和方法只让可信的类或者对象操作,对不可信的进行信息隐藏。数据抽象转载 2017-10-29 17:50:00 · 333 阅读 · 0 评论 -
C++三大特性 -- 多态
转载自:http://www.cnblogs.com/quincyhu/p/5867504.html概念多态(Polymorphisn)多态性是允许你将父对象设置成为和一个或更多的他的子对象相等的技术,赋值之后,父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作。简单的说:允许将子类类型的指针赋值给父类类型的指针(一个接口,多种方法)。C++ 支持两种多态性转载 2017-10-29 17:40:33 · 318 阅读 · 0 评论 -
编写一个函数,返回整型数组中的第二大值
#include using namespace std;int func(const int a[], int len){ if (a == NULL) return -1; if (len < 2) { cout<<"数组长度小于2, 无需比较"<<endl; return a[0]; } int max = a[0]; int second = a[0];原创 2017-10-30 19:49:56 · 1390 阅读 · 0 评论 -
【C++11】新特性——引入nullprt
转自:http://blog.csdn.net/huang_xw/article/details/87643461. 引入nullptr的原因引入nullptr的原因,这个要从NULL说起。对于C和C++程序员来说,一定不会对NULL感到陌生。但是C和C++中的NULL却不等价。NULL表示指针不指向任何对象,但是问题在于,NULL不是关键字,而只是一个宏定义(macro)。1转载 2017-12-10 14:46:40 · 338 阅读 · 0 评论 -
类String的构造函数、拷贝构造函数、析构函数和赋值函数的实现
// 类Stringclass String{public: String(const char *str = NULL); // 构造函数 String(const String &other); // 拷贝构造函数 ~String(void); //析构函数 String &operator = (const String &other); //赋值函数...原创 2018-04-13 16:22:28 · 443 阅读 · 0 评论 -
memcpy函数改进版memcpyEx函数源码
memcpy函数用于拷贝内存,但是该函数天生带有缺陷,即没有考虑内存重叠的情况。改进版拷贝速率比memcpy拷贝速率慢。 // 内存拷贝函数改进版,考虑内存重叠情况void *memcpyEx(void *dst, const void *src, size_t len){ if (dst == NULL || src == NULL) return NULL...原创 2018-08-06 11:23:28 · 483 阅读 · 0 评论 -
自己实现简单的类vector容器
只是一个简单的类vector容器,其内存是连续的 ,类似于数组。暂未实现迭代器,等有时间再研究吧。代码比较容易理解,在此基础上可以进行扩展。//---------------------------------------------------------------------// vector_sp.h// @Author : Shaoguang.// @Date : 201...原创 2018-08-28 22:24:17 · 785 阅读 · 0 评论 -
C/C++:CV限定的理解
文章来源于:http://jingyan.baidu.com/article/f0062228dcc8a6fbd3f0c88a.htmlC/C++提供多种声明变量和函数存储持续性、作用域和链接性的关键字,有些被称为存储说明符(store class specifier)或 cv 限定符(cv-qualifier),这里就一起学习一下cv限定符。cv限定符就是const和转载 2017-10-07 02:48:15 · 3366 阅读 · 0 评论