读取文件
逐条读取
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main() {
std::ifstream file1("1.txt"); //此处的字符串为文件的路径
string my_read;
while(getline(file1, my_read))
cout << my_read;
file1.close();
}
写入文件
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main() {
std::ofstream file1("1.txt");
string a = "测试";
file1 << a;
file1.close();
}