1 预处理指令 # include <>
#include <filename>
添加系统头文件。
#include "filename"
添加自定义头文件。
# include <iostream> 对应使用cout cin的情况下需要添加
# include <string> 对应使用字符串情况
# include <fstream> 对应使用ifstream ofstream情况
ifstream in("input.txt");
ofstream out("ouput.txt");
2 检查是否成功打开 in.is_open()
未打开报错 return 1;
if (!in.is_open()) {
cerr << "Error !" << endl;
return 1;
}
3 对txt文件逐行获取 while(getline(in, s)) {}
4 写入输出文件并添加换行符 out << s << "\n";
# include <fstream>
# include <iostream>
# include <string>