与freopen的区别在于多了一个文件流类型的形参。即例程中的stream1。
int main()
{
int a, b;
FILE *stream1;
freopen_s(&stream1, "in.txt", "r", stdin);
freopen_s(&stream1, "out.txt", "w", stdout);
while (cin >> a >> b)
cout << a + b << endl; // 注意使用endl
fclose(stdin);//关闭文件
fclose(stdout);//关闭文件
return 0;
}
————————————————
版权声明:本文为CSDN博主「蔡得伊比」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44391390/article/details/89186971