C/C++
文章平均质量分 72
freeangeles
这个作者很懒,什么都没留下…
展开
-
C++下超强内置类型定义
typedef char C8;typedef unsigned char U8;typedef short S16;typedef unsigned short U16;typedef int S32;typedef unsigned int U32;typedef long long S64;typedef unsigned long long U64;typedef con原创 2016-08-25 22:42:17 · 867 阅读 · 0 评论 -
C++Windows下创建多级目录
#include #include #include #pragma comment( lib, "Shlwapi.lib" )#include bool CreateMultipleDirectory( LPCTSTR pDirectory ){ if( NULL == pDirectory ) { return false; } //目录或文件已存在 if( Path原创 2015-10-19 15:40:58 · 3893 阅读 · 0 评论 -
C++Windows下递归遍历多级目录
#include #include #include #pragma comment( lib, "Shlwapi.lib" )#include bool ForeachFileByDirectory( LPCTSTR pDirectory ){ if( NULL == pDirectory ) { return false;原创 2015-10-19 17:15:34 · 2312 阅读 · 0 评论 -
C++Windows下CONTAINING_RECORD宏的用法和详解
#include #include int main(){ struct ABCD { int a; int b; int c; int d; }; //CONTAINING_RECORD宏的作用就是根据结构体 //类型和结构体中成员变量地址和名称则可求出 //该变量所在结构体的指针 ABCD Abcd = { 1, 2, 3, 4 }; //假设我们知道AB原创 2015-10-20 10:44:52 · 5267 阅读 · 0 评论 -
C++Windows下如何让窗口进程只运行一个实例
为了方便我们新建一个名为MFCTest的MFC对话框项目然后打开找到CMFCTestApp::InitInstance()函数添加单实例检测代码:BOOL CMFCTestApp::InitInstance(){ ////////////////////////////////////////////////////////////////////////// //单实例检测 tr原创 2015-10-20 11:46:16 · 3084 阅读 · 1 评论 -
C++高级排序算法详解
#include #include #include #define XT( str ) #str #define CNT_ARY( ary ) ( sizeof( ary ) / sizeof( ary[ 0 ] ) ) typedef int s32; typedef unsig原创 2016-06-12 21:11:03 · 1346 阅读 · 0 评论 -
C++基本排序算法详解
#include #include #include #define XT( str ) #str #define CNT_ARY( ary ) ( sizeof( ary ) / sizeof( ary[ 0 ] ) ) typedef int s32; typedef unsigned int u32; //[注意下面都是以降序排序进行说明] //1原创 2016-06-11 16:39:20 · 697 阅读 · 0 评论 -
WIN7+VS2008+C++下7zipSDK压缩解压缩的使用
1.官方最新版下载地址http://www.7-zip.org/sdk.html下载下来的文件如图:打开下面这个目录:打开VS2008命令工具:将命令行指定到刚才的目录中并输入nmake进行编译中:如果出现/OPT:NOWIN98 链接错误 输入nmake NEW_COMPILER=1 MY_STATIC_LINK=1 重新编原创 2015-10-13 11:31:58 · 7689 阅读 · 1 评论 -
C++下利用Command设计模式实现undo和redo
Command.hpp:#ifndef _COMMAND_HPP#define _COMMAND_HPP#include #include #include class Command{public: Command(){} virtual ~Command(){} virtual void Execute() = 0;};class InputC原创 2016-06-29 11:44:18 · 3038 阅读 · 0 评论 -
C++设计模式系列之一创建型模式
1.简单工厂模式Factory.hpp:#ifndef _FACTORY_HPP_#define _FACTORY_HPP_#include class Product{ public: virtual ~Product(){} protected: Product(){}};class XXProduc原创 2016-06-21 21:02:21 · 977 阅读 · 0 评论 -
WIN7+VS2010下编译Lua_5.2.3
1.官方最新版Lua下载地址:http://www.lua.org/download.html2.编译步骤原创 2014-08-30 16:05:38 · 1295 阅读 · 0 评论 -
WIN7+VS2010下配置编译Boost_1.55
1.官方最新版下载地址:http://www.boost.org/2原创 2014-08-27 19:34:42 · 3385 阅读 · 0 评论 -
C++下适合系统自动流程的棋牌游戏服务器桌子类
//适合自动流程的棋牌游戏桌子类class MyXXTable{public: MyXXTable() { //绑定回调数据 mMyStatus[ eGS_1 ] = MyStatus( &MyXXTable::OnStatus1, eGS_2, 2000 ); mMyStatus[ eGS_2 ] = MyStatus( &MyXXTable::OnStatus2, eG原创 2016-06-14 20:33:32 · 3314 阅读 · 0 评论 -
C++下棋牌游戏高性能洗牌算法
#include #include #include #include #include int GCardSrc[54];void ShuffleCard( int *pDestCard, int PlayerCardCnt, int PlayerCnt ){ assert( nullptr != pDestCard ); assert( PlayerCardCnt *原创 2016-08-06 12:27:20 · 3301 阅读 · 0 评论 -
C++经典面试算法题
#include #include #include ////////////////////////////////////////////////////////////////////////// // C++ 经典面试算法题 [7/28/2016 FreeAngel] //1.实现strcpy. char* MyStrCpy( char *pDest, const原创 2016-03-01 10:58:38 · 11683 阅读 · 2 评论 -
C++简单多线程事件驱动同步通知到主线程
#include #include #include #include #include #include typedef int s32;typedef unsigned u32;typedef float f32;class LockObject { public: LockObject() {原创 2016-06-18 10:57:48 · 5420 阅读 · 0 评论 -
C++设计模式系列之二结构型模式
1.Adapter模式Adapter.hpp:#ifndef _ADAPTER_HPP#define _ADAPTER_HPP//第三方库namespace ThirdPartyNameSpace{ class ThirdPartyClass { public: ThirdPartyClass(){} ~ThirdPartyClass(){}原创 2016-06-24 21:11:25 · 2203 阅读 · 0 评论 -
C++设计模式系列之三行为型模式
1.Iterator模式Iterator.hpp:#ifndef _ITERATOR_HPP#define _ITERATOR_HPP#include struct Player{ int mPID;};class PlayerManager{ public: PlayerManager() :mBeginIter( &mPlayers原创 2016-06-25 19:52:25 · 920 阅读 · 0 评论 -
WSAEventSelectI/O模型中FD_WRITE事件的处理以及如何发送数据
网上很多人都在问什么时候才会触发FD_WRITE,触发了我该怎么发送数据,如果没有触发,我又该如何发数据?当第一次连接成功的时候会触发FD_WRITE,还有就是当send 返回SOCKER_ERROR并且 WSAGetLastError()返回 WSAEWOULDBLOCK 这时表示缓冲区已满,当数据发送出去,又有空闲的缓冲区时会触发FD_WRITE,表示缓冲区可写。也就是说只有缓原创 2014-05-20 10:30:10 · 2171 阅读 · 0 评论 -
利用OpenCV将图片反色
#include #include INT APIENTRY wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPWSTR lpCmdLine, __in int nShowCmd ){ //加载一张图片,随便找一张jpg图片放到跟Main.cpp同目录改成test.jpg即可 Ipl原创 2014-08-26 14:36:23 · 2812 阅读 · 0 评论 -
WIN7+VS2010下配置编译SQLite_3.8.6
1.官方最新版下载地址:http://www.sqlite.org/download.html2.原创 2014-08-27 15:53:52 · 1562 阅读 · 0 评论 -
C++实现多线程对象内存池带垃圾回收机制
#include #include #include #include #include #include #include #include typedef int s32;typedef unsigned int u32;typedef char c8;//////////////////////////////////////////////////////////原创 2016-06-03 21:43:50 · 2821 阅读 · 0 评论 -
C++实现多线程全局内存池
1.内存池数据结构示意图:2.下面是完整实现代码包括与常规new,delete分配内存性能对比:#include #include #include #include #include #include #include typedef int s32;typedef unsigned int u32;typedef char c8;typed原创 2016-06-07 23:44:23 · 3617 阅读 · 2 评论 -
C++基本数据类型简便定义
// Test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"typedef char c8;typedef unsigned char u8;typedef short s16;typedef unsigned short u16;typedef int原创 2016-04-27 22:22:23 · 878 阅读 · 0 评论 -
如何在圆内随机点坐标
#include #include #include using namespace std;int main(){ //思路就是围绕这个坐标为圆心,产生不同半径的圆,然后在取这个圆上,不同角度或方向的点即可 typedef struct tagPoint { float x; float y; } Point; //圆心坐标 const Point CycPoin原创 2014-10-24 15:45:25 · 8945 阅读 · 4 评论 -
字符串拷贝函数strcpy的几种实现思想方式
#include <iostream> #include <assert.h>//strcpy标准实现char* CustomStrCpy1( char* Dest, const char* Src ){ if( nullptr == Dest || nullptr == Src ) { assert( false ); return nullptr; } char* p = Dest; while( *p++=*Src++ ); return Dest;}原创 2014-05-22 11:16:28 · 2299 阅读 · 0 评论 -
extern关键字的几种作用
1.修饰变量如:extern int GCount;原创 2014-05-27 11:08:20 · 2416 阅读 · 0 评论 -
C++如何导出DLL
1.导出全局函数2.导出原创 2014-09-06 11:47:10 · 2309 阅读 · 0 评论 -
超快速理解const修饰的作用
int main(){ int Temp1 = 0; int temp2 = 0; //const 在*号左边修饰则p指向的变量是一个常量 //根据上面的说则有下面两种写法,意思都是一样的 //1.p认为指向的是常量则:不能通过p修改指向变量的值 //2.p自己不是常量则:不用初始化赋值,p可以修改指向的地址 const int* p1;//可以不用初始化赋值 p1 = &Tem原创 2014-06-26 10:09:03 · 910 阅读 · 0 评论 -
利用数学知识快速理解按位与& 按位或| 按位异或^ 按位取反~
#include int main(){ int Test0 = 1; //二进制0001 int Test1 = 2; //二进制0010 //先来看按位与,直接理解为数学里面的两个集合求交集 //由于Test0和Test1二进制每个位没有交集则结果为0 printf( "%d\n", Test0 & Test1); //按位或,理解为数学里面的两个集合求并集 //由于T原创 2014-06-18 10:27:50 · 2667 阅读 · 2 评论 -
如何让一个变量存储多个不同的状态
#include #include typedef unsigned char BYTE;typedef unsigned short WORD;typedef unsigned long DWORD;BYTE GetBitCount( DWORD Number ){ BYTE Count = 0; while( Number ) { if( ( Number & 1 )原创 2014-06-25 16:38:43 · 1657 阅读 · 0 评论 -
字符串拷贝StringCbCopy函数和自定义CustomStrCpy函数和strcpy函数的性能对比
#include #include #include #include char* CustomStrCpy( char* Dest, const char* Src ){ memcpy( Dest, Src, strlen( Src ) + 1 ); return Dest;}int main(){ char Dest[ 128原创 2014-05-22 10:31:34 · 1582 阅读 · 0 评论 -
C++如何避免使用rand() % xxx的方式实现类似抽奖概率类的问题
头文件:#pragma once#include #include class Weight{ public: template static int GetWeightIndex( const T *pSrcWeight, size_t Size ) { if( 0 == pSrcWeight || 0 == Size ) { return ~0;原创 2015-09-28 11:39:36 · 4164 阅读 · 1 评论 -
C++ 联合体共享变量值的计算
输入下面代码: #include union stTest { int a; char b[2]; }; int main() { stTest t; t.a = 300; printf( "%u %原创 2015-09-17 11:32:36 · 1238 阅读 · 0 评论 -
C++下如何更好的定义结构体
int main(){ //如何更好的使用结构体 //例如RPG游戏中通常角色定义如下: struct Character { //基本数据 INT mCharID; INT mLevel; CHAR mName[ 32 ]; INT mExp; INT mJob; //货币 INT mCopper; INT mIngot; //属性点原创 2016-01-22 11:44:57 · 719 阅读 · 0 评论 -
C++下如何避免方法的方式并且安全的访问类的成员变量
#include class Test{public: Test() :mData( 0 ) ,mDataRef( mData ) {} ~Test() {} void DoSomething() { ++mData; }private:原创 2015-12-18 11:58:56 · 674 阅读 · 0 评论 -
C++如何将N维数组作为参数动态传给方法
#include "stdafx.h"//直接特例化模板参数templatevoid PrintArray( int pArray[ N ][ M ] ){ for( int i = 0; i < N; ++i ) { for( int j = 0; j < M; ++j ) { printf( "%d", pArray[ i ][ j ] ); } prin原创 2015-11-17 19:10:13 · 1439 阅读 · 0 评论 -
C++对象池完整实现
ObjectPool.hpp:#pragma once#include #include #include #include #ifndef nullptr#define nullptr 0#endiftemplateclass ObjectPool{ public: //初始化块大小如果能预先估算出块大小则性能达到最大 //即:只分配一次内存只释放一次内存原创 2015-10-16 10:38:50 · 5635 阅读 · 0 评论 -
C++多线程定时器完整实现
头文件:#pragma once#include #include #include //回调接口typedef struct ITimerEngineCallBack{ virtual bool OnTimerEngineCallBack( DWORD TimerID, DWORD Param ) = 0;}* ITimerEngineCallBackPtr;clas原创 2015-09-23 12:30:19 · 13259 阅读 · 1 评论 -
C++多线程Singleton模式
#include #include //锁class LockObject{ public: LockObject() { InitializeCriticalSection( &mLock ); } virtual ~LockObject() { DeleteCriticalSection( &mLock ); } void Lock()原创 2015-09-22 15:29:13 · 916 阅读 · 0 评论