華爲OJ練習題 -- c 語言IO重定位

在OJ 練習時發現scanf等IO操作並不需要直接通過控制檯輸入輸出,對調試效率極大提高

通過接口 freopen 可以實現此操作


#include <stdio.h>
#include <stdlib.h>
  
int main ()
{
    freopen("in.txt","r",stdin);     //從in.txt 中讀入數據
    freopen("out.txt","w",stdout);  // 將最後數據寫入out.txt中
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)     //數據是從in.txt中輸入的
        printf("%d\n",a+b);             //寫入out.txt中
    fclose(stdin);
    fclose(stdout);
    
    
    return 0;
}
    

 

參考 https://blog.csdn.net/xuan_liu123/article/details/62044623

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章