#include<iostream>
#include <fstream>
using namespace std;
/*文本文件
void main() {
char* fname = "d://dest.txt";
ofstream fout(fname);
//如果节点流发生致命错误返回true
if (fout.bad())
{
return;
}
fout << "i love youasdasdasdasdasdasd" << endl;
fout << "112asdsdasdasdasdasdas" << endl;
fout << "2" << endl;
fout.close();
if (fout.bad()) {
return;
}
ifstream fin(fname);
char *line ="";
const int LINE_LENGTH = 51;
char t[LINE_LENGTH];
char str[LINE_LENGTH];
while (fin.getline(str,LINE_LENGTH))
{
cout << "Read from file: " << str << endl;
}
system("pause");
};*/
//拷贝二进制文件
void main() {
char* fname = "d://a.jpg";
char* fname2 = "d://b.jpg";
//读入文件 以二进制方式
ifstream fin(fname,ios::binary);
//读取 以二进制方式
ofstream fout(fname2,ios::binary);
if (fin.bad()||fout.bad())
{
return;
}
while (!fin.eof())
{
char buff[1024] = { 0 };
fin.read(buff,1024);
fout.write(buff,1024);
}
fin.close();
fout.close();
getchar();
}
c++文件操作
最新推荐文章于 2023-08-03 17:11:34 发布