程序从文件中读取数据
- 方法1
freopen("a.txt","r",stdin);
- 方法二
#include<fstream>
ifstream cin("a.txt");
将信息保存在文件中
- 若想将有些信息保存到文件中,有些正常输出到屏幕中
#include<fstream>
int main(){
ofstream fout;
fout.open("res.txt");
//输出到屏幕
cout<<"hello";
//输出到文件res.txt中
fout<<"hello";
//other code
fout.close();
}
若想将信息输出到另外一个文件中,需要先关闭当前文件输出流,在打开另一个文件的输出流。