关于使用freopen重定向输入
-
调试程时,每次运行程序都要输入重复测试数据,太麻烦
-
可以将测试数据存入文件,然后用freopen将输入由键盘重定向为文件,则运行程序时不再需要输入数据了
#include <iostream>
using namespace std;
int main()
{
// 两个斜杠,c和c++要表示1个斜杠就要写两个斜杠
freopen("c:\\temp\\test.txt", "r", stdin);
//此后所有输入都来自文件C:\temp\test.txt
int n, mx = 0;
while (cin >> n)
{
if (n > mx)
mx = n;
}
cout << mx << endl;
return 0;
}