#include <iostream>
#include <string>
#include <fstream>
using namespace std;
/*
把partern01.cpp文件拷贝一个副本,重命名为newfile.txt
判断文件是否结束:fin.eof() == true 表示读到文件末尾
判断文件是否正常:fin.fail() == true 表示读文件流异常
fin.good() == true 表示读文件流正常
if(fin) 表示读文件流正常
*/
int main()
{
//ifstream fin("C://0/partern01.txt");
ifstream fin("./day05/1.格式化输出.cpp"); //当前位置是当前项目
//判断读文件流是否正常打开
if (fin.fail())
{
cout << "打开文件失败" << endl;
return -1;
}
ofstream fout("C://0/newfile.txt");
//判断写文件流是否正常打开
if (!fout)
{
cout << "写文件失败" << endl;
fin.close();
return -1;
}
//按行读
char buffer[100];
while (!fin.eof())
{
fin.getline(buffer, 100);
fout.write(buffer, strlen(buffer));
fout.put('\0');
}
//关闭文件流
fout.close();
fin.close();
return 0;
}