摘要:// 打开文件,获得文件流 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();
阅读全文
摘要:/*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...
阅读全文
摘要:版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明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回无法输出中文字符。
阅读全文
摘要:转帖,转帖位置忘了使用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
阅读全文
摘要:#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
阅读全文
摘要:这里有一段非常简单的代码,取自网络,我稍加修改,贴在这里。用来检查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
阅读全文
摘要:这个贴子记不起来是在哪里看的了。向原作者表示一下敬意!我在FreeBSD下试验成功过,CPU是P41.7G。使用CPU时间戳进行高精度计时对关注性能的程序开发人员而言,一个好的计时部件既是益友,也是良师。计时器既可以作为程序组件帮助程序员精确的控制程序进程,又是一件有力的调试武器,在有经验的程序员手里可以尽快的确定程序的性能瓶颈,或者对不同的算法作出有说服力的性能比较。在Windows平台下,常用的计时器有两种,一种是timeGetTime多媒体计时器,它可以提供毫秒级的计时。但这个精度对很多应用场合而言还是太粗糙了。另一种是QueryPerformanceCount计数器,随系统的不同可以提
阅读全文
摘要: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的执行,他需要一个输入
阅读全文
摘要:下面是一个使用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
阅读全文