用freopen重定向输入

调试程序时,每次运行程序都要输入测试数据,太麻烦

可以将测试数据存入文件,然后用freopen将输入由键盘重定向问文件,则运行程序时不再需要输入数据了

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	FILE *stream;
	freopen_s(&stream,"c:\\Users\\admin\\Desktop\\4.20.txt", "r", stdin);
	int n, max = 0;
	while (cin >> n)
	{
		if (n > max)
			max = n;
	}
	cout << max;
}

猜你喜欢

转载自blog.csdn.net/go__straight/article/details/89415944
今日推荐