如何把文件流作为参数传递c++ 就是fstream 这个头文件

来源:百度知道 编辑:UC知道 时间:2024/07/06 16:18:01

引用传递。 举例:

#include<iostream>
#include<fstream>
using namespace std;
ofstream& function(ofstream &ofs)
{
return ofs;
}
int main()
{
ofstream ofs("in.txt");
function(ofs);
return 0;
}

//最简单的实例
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream in("datain.txt");
ofstream out("dataout.txt");
int n;
in>>n;
out<<n;
return 0;
}