C++ 输入输出流的引用调用

输入输出流采用引用调用可以事先不用传文件名

#include<fstream>

using namespace std;

void print_row(ofstream& out, char c, int n);

int main()
{
	ofstream outfile;
	outfile.open("out2.txt");
	print_row(outfile, 'c', 10);
	outfile.close();
	return 0;
}

void print_row(ofstream& out, char c, int n)
{
	for(int i=0;i<n;i++)
		out<<c<<endl;
}


你可能感兴趣的:(C++ 输入输出流的引用调用)