文件的读取
#include "iostream"
#include "fstream"
#include "stdlib.h"
#include <string>
ifstream infile;
infile.open("F:\\桌面\\Code\\text.txt", ios::in); //文件的位置
if (!infile.is_open())
{
cout << "文件打开失败" << endl;
infile.close();
}
double x1;
infile >> x1; //用来读取数据
infile.close(); //读取完毕,释放文件
文件的输出
#include "iostream"
#include "fstream"
#include "stdlib.h"
#include <string>
ofstream ofs;
ofs.open("F:\\桌面\\Code\\file1.txt", ios::out);
if (!ofs.is_open())
{
ofs.close();
}
ofs << "ABCD" << "\n";
ofs << "abcd"<< "\n";
ofs.close();