c++文件复制

摘要: 转帖,转帖位置忘了使用C++标准程序库的输入输出流(I/O Stream)复制文件,存在许多的方法,方法一:逐个字符复制#include std::ifstream input("in",ios::binary);std::ofstream output("out",ios::binary);char ch;while (input.get(ch)) output >ch读取字符,则必须先调用input.unsetf(ios::skipws)取消输入流默认的跳过空白符的输入格式,因为换行符是空白符的一种。(BEN注:流失操作以空白字符'/0 阅读全文
posted @ 2011-05-18 21:34 几百人有爱 阅读(618) 评论(0) 推荐(0) 编辑

使用zzip和minizip解压缩文件

摘要: #include #include #include #include #include #include #ifdef _DEBUG#pragma comment( lib, "zlib_d.lib")#pragma comment( lib, "zzip_d.lib")#pragma comment( lib, "minizip_d.lib")#else#pragma comment( lib, "zlib.lib" )#pragma comment( lib, "zzip.lib" )#p 阅读全文
posted @ 2011-05-18 18:44 几百人有爱 阅读(533) 评论(0) 推荐(0) 编辑

测试CPU品牌和当前工作频率

摘要: 这里有一段非常简单的代码,取自网络,我稍加修改,贴在这里。用来检查CPU的生产商和品牌,以及当前工作频率,如果是台式机CPU,频率应该恒定,但是移动版本的CPU,频率不停地在变。以下代码用Visual C++编译,因为内嵌一点汇编,造成移植性变差(例如:GCC汇编跟AT&T汇编语法类似,但是MS汇编跟Intel汇编语法类似),以下代码如果希望在MinGW(GCC)下编译,需要修改那点内嵌的汇编。#include "stdafx.h"#ifndef CPUID_HPP_#define CPUID_HPP_#include #include #include #incl 阅读全文
posted @ 2011-05-18 00:54 几百人有爱 阅读(280) 评论(0) 推荐(0) 编辑

使用CPU时间戳进行高精度计时

摘要: 这个贴子记不起来是在哪里看的了。向原作者表示一下敬意!我在FreeBSD下试验成功过,CPU是P41.7G。使用CPU时间戳进行高精度计时对关注性能的程序开发人员而言,一个好的计时部件既是益友,也是良师。计时器既可以作为程序组件帮助程序员精确的控制程序进程,又是一件有力的调试武器,在有经验的程序员手里可以尽快的确定程序的性能瓶颈,或者对不同的算法作出有说服力的性能比较。在Windows平台下,常用的计时器有两种,一种是timeGetTime多媒体计时器,它可以提供毫秒级的计时。但这个精度对很多应用场合而言还是太粗糙了。另一种是QueryPerformanceCount计数器,随系统的不同可以提 阅读全文
posted @ 2011-05-17 01:13 几百人有爱 阅读(1224) 评论(0) 推荐(0) 编辑

在C++中使用CPU ID指令获得CPU信息

摘要: 1、什么是cpuid指令 CPUID指令是intel IA32架构下获得CPU信息的汇编指令,可以得到CPU类型,型号,制造商信息,商标信息,序列号,缓存等一系列CPU相关的东西。2、cpuid指令的使用 cpuid使用eax作为输入参数,eax,ebx,ecx,edx作为输出参数,举个例子:__asm{mov eax, 1cpuid...} 以上代码以1为输入参数,执行cpuid后,所有寄存器的值都被返回值填充。针对不同的输入参数eax的值,输出参数的意义都不相同。 为了更好的在C++中使用cpuid指令,可以使用类对指令进行封装,在类中定义一个专门的函数负责cpuid的执行,他需要一个输入 阅读全文
posted @ 2011-05-16 12:01 几百人有爱 阅读(523) 评论(0) 推荐(0) 编辑

boost.property_tree使用示例

摘要: 下面是一个使用boost.property_tree来解析XML/INI文件的简单示例。使用boost.property_tree来作为配置文件的解析工具非常合适.#include #include #include #include #include #include #include #include #include #include #include #include int main( int argc , char *argv[] ){ std::string strConfigName( "" ); std::string strReportName( &qu 阅读全文
posted @ 2011-05-10 14:06 几百人有爱 阅读(377) 评论(0) 推荐(0) 编辑

CEGUI 动态生成 texture imageset image

摘要: unsigned long* CMD_GUI_GetSmallMapBuf()// render small map{DWORD color[6] ={D3DCOLOR_RGBA( 0, 0, 255, 255 ),D3DCOLOR_RGBA( 255 , 0, 255, 255 ),D3DCOLOR_RGBA( 0, 255, 255, 255 ),D3DCOLOR_RGBA( 0, 255, 0, 255 ),D3DCOLOR_RGBA( 255, 255, 0, 255 ),D3DCOLOR_RGBA( 255, 0, 0, 255 )};int i = 0;int j = 0;stat 阅读全文
posted @ 2011-03-03 23:01 几百人有爱 阅读(171) 评论(0) 推荐(0) 编辑

vs2005下的dirent.h

摘要: dirent.h是gcc下的一个头文件,而在VS2005中是没有的。这个文件中封装了几个对目录进行操作函数:static DIR *opendir (const char *dirname);static struct dirent *readdir (DIR *dirp);static int closedir (DIR *dirp);对于在linux->windows之间进行程序移植来讲常常会造成一些困扰,在网上仔细搜了一下,发现原来已经有位好同志写了相应的移植代码,如下所示:typedef struct dirent { /* name of current directory e 阅读全文
posted @ 2011-01-31 16:58 几百人有爱 阅读(388) 评论(0) 推荐(0) 编辑

boost format 格式控制输出(学习笔记)

摘要: #include #include using namespace boost;using namespace std;// 格式输出控制,(类似c++准准库中的sprintf)// int main(){ // format库的几种用法 //------------------------------------------ // 第一种: // 最接近printf() cout<< "First: " << format("%s: %d + % d = %d/n")%"sum"%1%2%(1+2); // 阅读全文
posted @ 2011-01-28 23:39 几百人有爱 阅读(255) 评论(0) 推荐(0) 编辑

boost lexical_cast 字符串数字间的字面转换(学习笔记)

摘要: 晕,编译错了#include #include #include /* @brief 实现数字和字符串之间的字面转换 如把123(int)转换成"123"(string) @remark 注意:要转换为数字的字符串不能包含数字、小数点和e/E以外的字符 如:0x100,123L等C++允许的字面数字都不被支持*/using namespace boost;using namespace std;int main(){ //-------------------- // 字符串字面转成数字 //-------------------- int x = lexical_cast 阅读全文
posted @ 2011-01-25 22:46 几百人有爱 阅读(498) 评论(0) 推荐(0) 编辑