#undef THIS_FILE static char THIS_FILE[] = __FILE__;

http://blog.csdn.net/ljh56789/article/details/8071559
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
// zuoye07.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "zuoye07.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif DWORD BufferSize=1024; char buf[1024]; / // The one and only application object CWinApp theApp; using namespace std; void FileReadWrite_NoBuffer(char*source,char*destination); int _tmain(int argc,TCHAR*angv[],TCHAR*envp[]) { int nRetCode=0; printf("Call FileReadWrite_NoBuffer!\n"); //调用FileReadWrite_NoBuffer(char*source,char*destination)函数 FileReadWrite_NoBuffer("source.txt","nobuffer.txt"); return nRetCode; } void FileReadWrite_NoBuffer(char*source,char*destination) { HANDLE handle_src,handle_dst; DWORD NumberOfByteWrite; bool cycle; char*buffer; buffer=buf; //创建文件source.txt handle_src=CreateFile(source, GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_FLAG_NO_BUFFERING, NULL); //创建文件nobuffer.txt handle_dst=CreateFile(destination, GENERIC_WRITE, NULL, NULL, OPEN_ALWAYS, NULL, NULL); //判断文件是否创建失败,若失败打印输出提示信息并退出 if(handle_src==INVALID_HANDLE_VALUE || handle_dst==INVALID_HANDLE_VALUE) { printf("File Create Fail!\n"); exit(1); } cycle=true; while(cycle) { NumberOfByteWrite=BufferSize; //读取文件source.txt if(!ReadFile(handle_src,buffer,NumberOfByteWrite,&NumberOfByteWrite,NULL)) { //读取文件source.txt失败 printf("Read File Error!%d\n",GetLastError()); exit(1); } if(NumberOfByteWrite<BufferSize)cycle=false; //写入文件nobuffer.txt if(!WriteFile(handle_dst,buffer,NumberOfByteWrite,&NumberOfByteWrite,NULL)) { //写入文件nobuffer.txt失败 printf("Write File Error!%d\n",GetLastError()); exit(1); } } //关闭文件句柄(source.txt,nobuffer.txt) CloseHandle(handle_src); CloseHandle(handle_dst); }
最新发布
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值