mingw64 + sublime 3 输入输出文件不起作用 [英] mingw64 + sublime 3 input output files not working

查看:87
本文介绍了mingw64 + sublime 3 输入输出文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为竞争性编程建立一个环境.我已经成功安装了带有 sublime 3 的 mingw 64.我的代码能够在控制台中打印 hello world.但是,我无法将输入和输出读入输入和输出文件.我正在按照此处的说明进行操作,并且这是我试图运行的 C++ 代码.

I am trying to set up an environment for competitive programming. I have successfully installed mingw 64 with sublime 3. My code is able print hello world in the console. However, I am unable to read inputs and output into the input and output files. I am following the instructions here and this is the c++ code that I am trying to run.

#include<iostream>
using namespace std;
int main(){

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    cout << "Hello world";
    int var;
    cin >> var;
    cout << var;
}

我的 input.txt 文件中有整数 5.当我使用 C++ 单个文件构建并运行时,什么也没有发生,控制台只显示 [Finished in 5.6s].我希望代码能够读取我放在 input.txt 文件中的输入并将它们输出到 output.txt 文件中.当我删除 2 freopen 代码时,Hello world 被打印到我的控制台上.我可以知道我在这里做错了什么吗?谢谢!

I have the integer 5 in my input.txt file. When I build with c++ single file and run, nothing happens and the console just says [Finished in 5.6s]. I hoping that the code will read inputs that I place in the input.txt file and output them to the output.txt file. When I remove the 2 freopen code, Hello world is printed onto my console. May I know what am I doing wrong here? Thank you!

推荐答案

我遇到了类似的问题,结果 Windows Defender 阻止了对 output.txt 文件的编辑(Windows Defender 中添加了一项名为 Controlled folder access 的新功能).检查您的目录是否不包含在该功能中.您是否在 Sublime 中使用 C++ 的默认构建系统?检查路径是否正确

I had a similar problem and it turns out windows defender was blocking edit to output.txt file (A new feature has been added in windows defender called Controlled folder access). Check if your directory is not included in that feature. Are you using the default build system for c++ in Sublime? Check paths are correct

这篇关于mingw64 + sublime 3 输入输出文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆