![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c/c++
文章平均质量分 65
zes11478
这个作者很懒,什么都没留下…
展开
-
模板函数需要将声明和实现放到同一个文件中
模板函数需要将声明和实现放到同一个文件中//templateTest.h#ifndef TEMPLATE_TEST_H_H#define TEMPLATE_TEST_H_Hbool IsEqual(int i1, int i2);templatebool IsEqualEx(Type_& t1, Type_& t2);class MyClass{public: M转载 2016-03-24 20:16:54 · 1044 阅读 · 0 评论 -
std::numeric_limits<int>::min()报错
用【std::numeric_limits::min()】的时候,发现了一个奇怪的现象,如下://#include /*一旦【std::numeric_limits::min();】之前有【#include 】,就会出现如下错误。懒得找具体原因了。source.cpp(6): warning C4003: not enough actual parameters for macro '原创 2016-04-08 14:23:39 · 3035 阅读 · 2 评论 -
用8进制和16进制创建字符串
开始#include // 8进制Oct(octonary)//10进制Dec(decimal)//16进制Hex(hexadecimal)int main(){ //我想将一个16/8/10进制的数字赋值给一个int: //16进制的数字,开头是0x // 8进制的数字,开头是0 //10进制的数字,是什么就写什么(别以0开头,以0开头,就成八进制了转载 2016-04-11 20:08:57 · 1616 阅读 · 0 评论 -
C++使用for和foreach,g++编译C++11程序
Windows的for each在Linux下编译不过去,所以找了一下C++使用foreach的通用方式。//C++11 lambda 表达式解析//http://www.cnblogs.com/haippy/archive/2013/05/31/3111560.html//C++ 中的 Lambda 表达式//https://msdn.microsoft.com/zh-cn/libra转载 2016-08-19 09:24:32 · 4835 阅读 · 0 评论 -
std::strstream和std::stringstream
开始#include //std::stringstream(推荐使用)#include //std::strstream(已废弃)#include templatestd::string ToString(Type_ num){ std::ostringstream ss; ss << std::fixed; ss.precision(9); ss转载 2016-09-26 14:49:24 · 3636 阅读 · 0 评论 -
VC++/VS重新打开Solution Explorer
使用VS2015时,手误关闭了Solution Explorer,怎么重新打开它呢?View->Solution Explorer。。转载 2017-03-01 20:14:27 · 12919 阅读 · 0 评论 -
在C和C++下声明函数指针的方式
在C的规范下,声明一个函数指针的方式如下://comm.h#ifndef COMM_H#define COMM_Hvoid test_print(const char*);void(*console)(const char*);//在C的时候,这样写算作一个声明.#endif//COMM_H//comm.c[注意是.c不是.cpp]#include "comm.h"#inclu原创 2017-04-05 15:16:02 · 3793 阅读 · 0 评论 -
用标准库获取微秒(micro)精度的时间型字符串
因为某些原因,需要经常获取高精度的可读的时间型字符串,能用标准库获取的话,更好。于是就有了下面的代码:#include #include #include #include #include //标准库下,几种时间类型的转换.void std_time_convert(){ char tmBuf[64] = { 0 }; //(操作系统精度的)时间点. s原创 2017-04-03 01:46:35 · 1929 阅读 · 0 评论 -
主线程循环接受命令
循环接收命令#include #include #include #include int main(){ for (char line[512]; printf("press [q] to quit...\n") && gets_s(line); ) { if (std::strcmp(line, "q") == 0) bre转载 2017-04-20 21:56:44 · 576 阅读 · 0 评论 -
float和double的内存布局
http://www.cnblogs.com/yaozhongxiao/archive/2010/09/08/1821185.htmlhttp://blog.csdn.net/demon__hunter/article/details/3566232已经有人写好了,我就不写了。一个人,只认识二进制,他要表达十进制中的9,需要写成1001,换算公式为1*2^3+0*2^2+0*2转载 2016-03-23 13:16:06 · 555 阅读 · 0 评论 -
我犯了一个低级的C++的逻辑错误
自己犯了一个低级错误。留作警示。#include #include #include #include #include #include struct MyNode{ int num; std::vector theBeg; std::vector theEnd;};void GenerateFile(std::string fileName)转载 2016-03-22 21:18:40 · 1150 阅读 · 0 评论 -
匈牙利命名法则
◆基本原则是:变量名=属性(比如m_)+类型(比如h)+对象描述(比如Wnd) ◆属性部分和类型部分前缀 类型a 数组 (Array)b 布尔值 (Boolean)by 字节 (Byte)==8 bitC 类(class)c 有符号字符 (Char)c_ const变量(const)cb 无符号字原创 2014-02-07 21:47:14 · 659 阅读 · 0 评论 -
位运算相关
@#本文部分摘录百科的“位运算”词条。程序中的所有数在计算机内存中都是以二进制的形式储存的。位运算说穿了,就是直接对整数在内存中的二进制位进行操作。比如,and运算(即&运算,而非&&运算)本来是一个逻辑运算符,但整数与整数之间也可以进行and运算。举个例子,6的二进制是110(即00000110),11的二进制是1011(即00001011),那么6 and 11(即6&11)的转载 2014-02-05 22:12:30 · 590 阅读 · 0 评论 -
popen函数相关
用popen函数可以获得命令的输出信息,可以输入信息来和程序交互比如,我用7z程序压缩了文件,压缩后,原文件可以认为没用了。应当删掉,如果压缩包有问题,但是原文件又删掉了,很显然不行,我们应当先测试压缩包是否正常,如果正常,就删掉原文件,否则,重新压缩,那么,用命令测试原文件,就需要popen命令了。7z.exe --help可以知道, t : Test integrity转载 2015-12-11 22:33:42 · 362 阅读 · 0 评论 -
C的指针变量的简单介绍
以函数指针为例,说一下C声明的解读:对于不会解读C的声明的朋友们,建议阅读一下《征服C指针》的第三章。现摘录《征服C指针》的第三章的第一节的第106页的一段话:C语言本来是美国人发明的,最好还是用英语来读。对于:int (*pf)(double);如果从pf开始以英语的顺序来读,应该是下面这样:pf is pointer to function returning int原创 2015-12-05 22:40:00 · 366 阅读 · 0 评论 -
函数对象(function object)的简单讲解
函数对象:有那么一个类,它重载了圆括号运算符“()”,用这个类创建了一个对象,当用该对象调用此操作符时,其表现形式如同普通函数调用一般,因此取名叫函数对象,又名仿函数。你可能需要先了解函数指针:http://blog.csdn.net/u013600225/article/details/50190043例子:int add(int a, int b){ return a + b; }原创 2015-12-05 23:14:46 · 638 阅读 · 0 评论 -
cpplinq中发现的const用法
开始。#include #include #include "cpplinq.hpp"class tm32bit{public: tm32bit(int _time = 0) :m_time(_time) {} bool operator<(const tm32bit& _that) /* */ { return m_time < _that.m_time ? tr原创 2016-01-28 21:41:20 · 878 阅读 · 0 评论 -
结构体如果没有重载比较运算符,不能直接进行比较
开始。#include struct dt64bit{ int m_date; int m_time;public: dt64bit() :m_date(0), m_time(0){} dt64bit(int _date, int _time) :m_date(_date), m_time(_time){}// bool operator<(cons转载 2016-01-29 00:49:54 · 1902 阅读 · 1 评论 -
一个类在调用构造函数时,各个数据成员的构造顺序。
一个类在调用构造函数时,各个数据成员的构造顺序。#include class ShowIndex{public: ShowIndex(int i) :i(i){ std::cout i << std::endl; } ~ShowIndex() { std::cout i << std::endl; }public: int i;};clas原创 2016-03-03 20:44:24 · 872 阅读 · 0 评论 -
C++的“友元类”的一个使用场景
我遇到了“必须使用友元类”的一个场景。我遇到了A中有B,B中有A的场景。貌似“A的一个函数,作为B的友元函数”这个需求无法被实现。#include class MyApiCls;class TcpClientCls//用于和Server通信{public: TcpClientCls(MyApiCls* pApi) :m_pApi(pApi){}public:转载 2016-03-08 17:32:12 · 1963 阅读 · 0 评论 -
std::map在遍历的过程中删除item的最好方式
看到了一种新的方法:#include #include void erase_1()//以前都是用的这个笨方法.{ std::map cache; for (int i = 1; i < 10; ++i) cache[i] = i * 10; //在遍历的过程中删除某个节点 for (bool reSerarch = true; reSer转载 2017-06-06 21:01:27 · 2015 阅读 · 0 评论