问题描述
我想在 vs code 中实现:在本地编译时,从 test.in 的文件中读取数据,并输出正确结果。
- 我已经在
c_cpp_properties.json中进行了定义:
"defines": [
// 省略
"LOCAL"
]
- 代码中也进行了定义:
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main()
{
#ifdef LOCAL
freopen("test.in", "r", stdin);
#endif
cin >> a >> b;
cout << a + b << endl;
return 0;
}
test.in中的数据也符合要求:
100 2
但是,当我编译代码时,依然要求我输入。例如,我输入 1 和 2,能输出正确结果 3。
我又在 devcpp 中编译了代码(已添加预处理命令),不需要我输入,且输出了正确结果 102。
希望各位能帮助我解决问题,感谢!