我开始 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;
}