华为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

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