在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
华为OJ练习题 -- c 语言IO重定位
最新推荐文章于 2024-04-14 15:58:55 发布