就是一个用来测试文件的读写的程序而已,不过这种方法比fopen好用多了,缺点是不能同时读写文件和标准输入输出。
#define LOCAL //如果要求的是标准输入输出,那就把#define LOCAL删了。
#include<stdio.h>
int main()
{
#ifdef LOCAL
freopen("datain.txt","r",stdin);
freopen("dataout.txt","w",stdout);
#endif // LOCAL
int x,n=0,s=0;
while(scanf("%d",&x)==1)
{
s+=x;
n++;
}
printf("%d %d",s,n);
return 0;
}
本来不想写这篇博客的,看到了百度上有人说把文件放在debug中,实测不行,只能放在程序对应的文件里。(最好不要使用路径)