C/C++编程:复制整个文件或文件的一半
代码思路:在copyFile.cpp中编写两个函数copyWholeFile和copyHalfOfFile,分别实现复制整个文件和文件一半的功能,然后在main.cpp中调用这两个函数。
copyFile.h
#ifndef _COPYFILE_H_
#define _COPYFILE_H_
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void copyWholeFile(const string &srcFilePath, const string &dstFilePath);
void copyHalfOfFile(const string &srcFilePath, const string &dstFilePath);
#endif
copyFile.cpp
#include "copyFile.h"
void copyWholeFile(const string &srcFilePath, const string &dstFilePath)
{
ifstream src(srcFilePath, ios::binary);
if (!src)
{
cerr << "Failed to open source file: " << srcFilePath << '\n';
return;
}
ofstream dst(dstFilePath, ios::binary);
if