【发布时间】:2020-03-11 22:03:47
【问题描述】:
我开始 C++ 的时间不长,并且非常努力地寻找不同的方法来读取和写入文件,但没有结果,直到我在 CodeBlocks 上尝试了它,它有效。虽然下面附有图像以指出代码中可能存在的错误两个应用程序使用了相同的代码。
错误代码: Severity Code Description Project File Line Suppression State Suppression State
Error C4996 'freopen': This function or variable may be unsafe. Consider using freopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. Codeforces C:\Users\owamoyo\source\repos\Codeforces\Codeforces.cpp 6
#include<bits/stdc++.h>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n; cin >> n;
while (n--) {
int x; cin >> x;
cout << x << " ";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n; cin >> n;
while (n--) {
int x; cin >> x;
cout << x << " ";
}
return 0;
}
【问题讨论】:
-
你有什么理由让自己首先经历这种痛苦吗?您正在做的事情使插入调试输出和其他有用的诊断变得烦人。您可以像普通的常规文件流一样打开 input.txt 和 output.txt 并对这些流进行操作。
-
不相关:出于多种原因使用代码is usually a bad idea 的图像。 So is
#include <bits/stdc++.h>. -
不过,出于兴趣,您需要做什么才能让 Visual Studio 接受
#include <bits/stdc++.h>?自己滚?从 GCC 中提取文件? -
MSVC 对有效代码发出警告,试图诱使您使用他们的专有东西
-
此处的所有问题都必须包含所有相关信息在问题本身中以纯文本形式。链接可以随时停止工作,使问题变得毫无意义。无法复制/粘贴以图像形式显示的代码、数据或错误;或编辑或编译以供进一步研究和调查。这个问题必须是edited,并且所有链接和图像都被删除并替换为所有相关信息,作为纯文本。所有代码必须满足minimal reproducible example 的所有要求。您可以在这里找到许多其他问题,其中包括纯文本形式的所有内容,我看不出为什么这个问题也不能。
标签: c++ visual-c++ codeblocks freopen