freopen 重定向输入

#include<iostream>
#include<cstdio>
#pragma warning(disable : 4996)

//freopen 重定向输入
//调试程序是,每次运行程序都需要输入测试数据,太麻烦
//可以将测试数据存储文件,然后用freopen将输入由键盘重定向为文件
//则运行程序是不需要输入数据了。

using namespace std;

int main() {
    
    freopen("test.txt", "r", stdin);
    //此后所有的输入都来自文件"test.txt
    int n, max = 0;
    while (cin>>n)
    {
        if (n > max)
            max = n;
    }
    printf("max = %d\n", max);
    
    return 0;

}

posted @ 2022-02-12 09:33  江南王小帅  阅读(53)  评论(0)    收藏  举报