fileop.cpp

来自「< Visual C++ 6.0实例教程》源代码, WinRAR自解压包」· C++ 代码 · 共 60 行

CPP
60
字号
// FileOP.cpp: implementation of the CFileOP class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FileExample.h"
#include "FileOP.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFileOP::CFileOP()
{

}

CFileOP::~CFileOP()
{

}

BOOL CFileOP::Copy(CString strSourcePath, CString strTargetPath)
{
	CFile fSource, fTarget;
	//定义4k字节的缓冲区
	char	c[4096];      
	int	nCount;  
	//打开文件
	if  (!fSource.Open(strSourcePath, CFile::modeRead))
	{
		AfxMessageBox("Open Source File Fail!");
		return  false;
	}
	if  (!fTarget.Open(strTargetPath, CFile::modeCreate | CFile::modeWrite))	
	{
		AfxMessageBox("Create Target File Fail!");
		return  false;
	}

	//读文件到缓冲区c
	nCount = fSource.Read(c, 4096);
	while (nCount)
	{
		fTarget.Write(c, nCount);
		nCount = fSource.Read(c, 4096);
	}
	fSource.Close();
	fTarget.Close();

	return true;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?