C++ freopen从文件自动读入数据

使用freopen可以从文件中直接读入数据,避免每次调试都重复的输入数据
术语:freopen重定向输入

#include
using namespace std;

int main(){
    
    freopen("C:\\Users\\DELL\\Desktop\\清华计算机算法MOOC\\课上写的代码\\第四周\\4_3_1_freopen_data.txt", "r", stdin);
    
    int c, mx = 0;
    while(cin >> c) {
        if(c > mx) 
            mx = c;
    }
    printf("%d", mx);
    return 0;
}

你可能感兴趣的:(C++ freopen从文件自动读入数据)