#include <iostream>
#include <cstring>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
char name[20];
char str[30];
cout << "请输入文件" << endl;
cin >> name;
outfile.open(name);
if (!outfile)
{
cout << "写入文件打开失败!";
exit(1);
}
cout << "请输入要写入的文件的数据:" << endl;
cin >> str;
outfile << str;
outfile.close();
infile.open(name);
if (!infile)
{
cout << "读文件打开失败:";
exit(1);
}
char c;
cout << "输出文件中数据" << endl;
while (infile.get(c))
{
cout << c;
}
cout << "\n";
infile.close();
}
c++使用ifstream和ofstream对象读写文件的功能
最新推荐文章于 2021-12-03 14:52:52 发布