随笔分类 - C++那点事
摘要:面向对象是C++的重要特性. 但是c++在c的基础上新增加的几点优化也是很耀眼的 就const直接可以取代c中的#define 以下几点很重要,学不好后果也也很严重 const1.限定符声明变量只能被读 const int i = 5; int j = 0; …… i = j; //非法,导致编译错误 j = i; //合法 2.必须初始化 const int i = 5; //合法 const int j; //非法,导致编译错误 3.在另一个文件中引用const常量 extern const int i; //合法 ...
阅读全文
摘要:#include "stdafx.h"#include using namespace std;/*位运算符实现 加 减 乘 除*///加法运算int add(int a, int b){ return b==0 ? a : add(a^b, (a&b)>= 1; } return result;}//乘法int multi(int a, int b){ if (isNegative(a)) { if (isNegative(b)) return multi_help(negative(a), negative(b)); ...
阅读全文
摘要:#include "stdafx.h"#include #include #include using namespace std;#define fn(x) int a##x; //声明一个ax变量 a常量 x变量#define tn(x) #x //可以直接拼一个字符串 int 可以直接输出 int//可以帮你写一个类#define cclass(cname,x,y,z) class C##cname\{\public:\ x m_##x;\ y m_2##y;\ char m_##z;\};//////////////////...
阅读全文
摘要:2013-12-17int _tmain(int argc, _TCHAR* argv[]){ #ifdef DEBUG cout Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions 中添加 DEBUG , 这样 操作同样会输出 cout<<"DEBUG has been defined"<<endl;∴,在多人开发项目的时候,如果你想让别人运行一段函数,而自己不想运行,则可以这样实现:(你需要使用上述第2步,添加 DEBUG 到自己的项目环境中)void
阅读全文
摘要:#include "stdafx.h"#include using namespace std;/*#大端模式(Big_endian):字数据的高字节存储在低地址中,而字数据的低字节则存放在高地址中。#小端模式(Little_endian):字数据的高字节存储在高地址中,而字数据的低字节则存放在低地址中。##union 型数据所占的空间等于其最大的成员所占的空间。对union 型的成员的存取都是#相对于该联合体基地址的偏移量为0 处开始,也就是联合体的访问不论对哪个变量的存取都#是从union 的首地址位置开始。如此一解释,上面的问题是否已经有了答案呢?#*/bool li
阅读全文
摘要:技术 对于我来说 是我前进的动力虽然有时候感觉会枯燥乏味 不过没关系 放松一下紧张的心态 做一些你能够是你进步的事情 这样 你才会觉得 每天都过得很充实 学海无涯 坚持追求你所想要实现的梦想 终归有一天 你会等到……那么 今天看到了 printf 的一些知识 感觉挺好 下面 我就来吐槽一下 : 《该博文以下内容的 测试平台及环境 win 64bit VS2012》http://www.cnblogs.com/hnrainll/archive/2011/08/05/2128496.html //从printf谈可变参数函数的实现原文地址:http://www.vimer.cn/2011/08/p
阅读全文
摘要:TCP// TCP_Server.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include #pragma comment (lib,"ws2_32.lib")using namespace std;void _tmain(int argc, _TCHAR* argv[]){ WSADATA wsData; //WinSock Async 环境数据 WSAStartup(0x0202, &wsD
阅读全文
摘要:#include "stdafx.h"#include using namespace std;class MyString{public: MyString(const char *str = NULL); //通用拷贝构造函数 MyString(const MyString &another...
阅读全文