UNIX Socket UDP 代码

摘要: 客户端#include #include #include #include #include #include #include #include // UDP 通讯程序代码-Clientint main(int argc, char* argv[]){ if (argc #include #include #include #include #include #include #include int main(){ // Create UDP socket int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (sock 0).. 阅读全文
posted @ 2011-10-30 20:27 几百人有爱 阅读(340) 评论(0) 推荐(0) 编辑

C语言常用排序全解

摘要: /*=============================================================================相关知识介绍(所有定义只为帮助读者理解相关概念,并非严格定义):1、稳定排序和非稳定排序 简单地说就是所有相等的数经过某种排序方法后,仍能保持它们在排序之前的相对次序,我们就说这种排序方法是稳定的。反之,就是非稳定的。 比如:一组数排序前是a1,a2,a3,a4,a5,其中a2=a4,经过某种排序后为a1,a2,a4,a3,a5,则我们说这种排序是稳定的,因为a2排序前在a4的前面,排序后它还是在a4的前面。假如变成a1,a4,a2,a. 阅读全文
posted @ 2011-09-19 17:05 几百人有爱 阅读(167) 评论(0) 推荐(0) 编辑

A*寻路初探 GameDev.net

摘要: 作者: Patrick Lester译者:Panic2005年3月18日译者序:很久以前就知道了A*算法,但是从未认真读过相关的文章,也没有看过代码,只是脑子里有个模糊的概念。这次决定从头开始,研究一下这个被人推崇备至的简单方法,作为学习人工智能的开始。这篇文章非常知名,国内应该有不少人翻译过它,我没有查找,觉得翻译本身也是对自身英文水平的锻炼。经过努力,终于完成了文档,也明白的A*算法的原理。毫无疑问,作者用形象的描述,简洁诙谐的语言由浅入深的讲述了这一神奇的算法,相信每个读过的人都会对此有所认识(如果没有,那就是偶的翻译太差了--b)。现在是2005年7月19日的版本,应原作者要求,对文中 阅读全文
posted @ 2011-09-19 16:37 几百人有爱 阅读(129) 评论(0) 推荐(0) 编辑

SetWinEventHook和SetWindowsHookEx的异同

摘要: SetWinEventHook 和 SetWindowsHookEx 都可以指定钩子函数(hook function)来截取别的进程中的消息,但是他们之间有一些不同。SetWindowsHookEx 有两种钩子函数,一种是全局钩子(global hook),另一种是线程钩子(thread hook)。全局钩子能够截取所有线程的消息,但是全局钩子函数必须存在于一个 dll 中。线程钩子只能截取属于当前进程中的线程的消息,钩子函数不需要放在 dll 中。SetWinEventHook 也有两种钩子函数,一种是进程内钩子(in-context hook),另一种是进程外钩子(out-of-conte 阅读全文
posted @ 2011-07-12 09:53 几百人有爱 阅读(408) 评论(0) 推荐(0) 编辑

wxWidgets 屏幕截图

摘要: wxScreenshotMaker.h#pragma once #include #ifdef __WXMAC__ #include #endif class wxScreenshotMaker { public: wxScreenshotMaker(); ~wxScreenshotMaker(); wxBitmap GetScreenshot(); private: #ifdef __WXMAC__ int screenWidth; int screenHeight; CGLContextObj glContextObj; ... 阅读全文
posted @ 2011-06-29 15:52 几百人有爱 阅读(407) 评论(0) 推荐(0) 编辑

Linux and windows Porting

摘要: // 根据本人的经验胡乱写写:// linux下获得可用磁盘空间大小采用: string sCmd = "df -m /usr/local | awk '{ if(NR == 2) print $4 }'"; string sResult = pipeIPC(sCmd); pipeIPC()如下:string pipeIPC(const string& command){ string sResult = ""; char *s = new char[2048]; bzero(s, 2047); FILE *fp = NULL; 阅读全文
posted @ 2011-06-07 21:30 几百人有爱 阅读(255) 评论(0) 推荐(0) 编辑

Zlib解压缩示例

摘要: 先上代码,压缩包的文件结构解析: zip=unzOpen(resItem->filename); if(0==zip) return false; done=unzGoToFirstFile(zip); while(done==UNZ_OK) { unzGetCurrentFileInfo(zip, &file_info, szZipName, sizeof(szZipName), NULL, 0, NULL, 0); _strupr_s( szZipN... 阅读全文
posted @ 2011-06-02 09:42 几百人有爱 阅读(865) 评论(0) 推荐(0) 编辑

std::ifstream 打开文件,获得文件流 并赋给std::string

摘要: // 打开文件,获得文件流 std::ifstream inFile(fileName.c_str(), std::ios::in | std::ios::binary); std::ostringstream oss; oss << inFile.rdbuf(); std::string buffer = oss.str(); inFile.close(); 阅读全文
posted @ 2011-05-20 18:32 几百人有爱 阅读(941) 评论(0) 推荐(0) 编辑

zlib 压缩文件

摘要: /*zlib 的z_stream结构*/typedef struct z_stream_s { Bytef *next_in; uInt avail_in; uLong total_in; Bytef *next_out; uInt avail_out; uLong total_out; char *msg; struct internal_state FAR *state; alloc_func zalloc; free_func zfree; voidp... 阅读全文
posted @ 2011-05-20 16:22 几百人有爱 阅读(688) 评论(0) 推荐(0) 编辑

fstream如何打开中文路径 - [C/C++]

摘要: 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://yzyanchao.blogbus.com/logs/35621328.html VS2005开始(似乎),用ofstream打开中文路径名会出现乱码问题,解决方法为:std::locale loc = std::locale::global(std::locale(""));std::ofstream fout(FilePath);//do some work herefout.close();std::locale::global( loc );不加最后一句,cout回无法输出中文字符。 阅读全文
posted @ 2011-05-19 14:15 几百人有爱 阅读(457) 评论(0) 推荐(0) 编辑