甚至无法在Sublime Text 3中构建简单的程序 [英] Can't build even a simple program in Sublime Text 3

查看:30
本文介绍了甚至无法在Sublime Text 3中构建简单的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从Python切换到C ++,以实现数据结构和算法.我发现Sublime Text 3安静而强大.我安装了它,将Mingw-64编译器添加到路径中,还添加了构建系统".我希望足以构建和运行任何基本的C ++程序.但是当我跑步

I have just switched from Python to C++ for implementing Data Structures and Algorithms. I found that Sublime Text 3 was quiet powerful. I installed it, added my Mingw-64 compiler to the path and also added a "build system". I hoped it would be suffice to build and run any basic C++ program. But when I run

#include <iostream>
using namespace std;

int main() {
   int n;
   cin>>n;
   cout<<n<<endl;
   return 0;
}

我知道,构建部分或编译器设置中都存在一些问题.我尝试了不同的编译器,从代码块到独立的Mingw-64编译器,均未成功.过去,我使用过代码块,它从不需要我创建exe文件或引用它.如果我重新启动该程序,它将显示权限被拒绝的错误,我知道它为什么会发生.

I know, there is some problem either in the build part or the compiler settings. I tried different compilers, from code blocks to independent Mingw-64 compiler without any success. In the past, I have used Code Blocks, it never required me to create an exe file or reference it. If I restart the program, it will show permission denied error which I know why it occurs.

这是错误:

系统找不到文件G:\ Programming \ C ++ \ second.exe.[在15.0秒内完成,退出代码为1]

The system cannot find the file G:\Programming\C++\second.exe. [Finished in 15.0s with exit code 1]

[shell_cmd:g ++"G:\ Programming \ C ++ \ second.cpp" -o"G:\ Programming \ C ++/second"&&"G:\ Programming \ C ++/second"] [dir:G:\ Programming \ C ++] [路径:C:\ Program Files(x86)\ NVIDIA Corporation \ PhysX \ Common; C:\ ProgramData \ Oracle \ Java \ javapath; C:\ WINDOWS \ system32; C:\ WINDOWS; C:\ WINDOWS \ System32 \ Wbem; C:\ WINDOWS \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Program文件(x86)\ ATI Technologies \ ATI.ACE \ Core-Static; C:\ ProgramFiles \ Intel \ WiFi \ bin \; C:\ Program Files \ Common文件\ Intel \ WirelessCommon \; C:\ Program Files(x86)\ Windows实时\共享; C:\ Program Files \ MATLAB \ MATLAB生产Server \ R2015a \ runtime \ win64; C:\ Program Files \ MATLAB \ MATLAB生产Server \ R2015a \ bin; C:\ Program Files \ MATLAB \ MATLAB生产Server \ R2015a \ polyspace \ bin; C:\ Python27 \; C:\ Python27 \ Lib \ site-packages \ PyQt4; C:\ ProgramFiles \ Git \ cmd; C:\ Program档案(x86)\ mingw-w64 \ i686-7.1.0-posix-dwarf-rt_v5-rev0 \ mingw32 \ bin; C:\ Users \ 80LM0141IH \ Anaconda3; C:\ Users \ 80LM0141IH \ Anaconda3 \ Library \ mingw-w64 \bin; C:\ Users \ 80LM0141IH \ Anaconda3 \ Library \ usr \ bin; C:\ Users \ 80LM0141IH \ Anaconda3 \ Library \ bin; C:\ Users \ 80LM0141IH \ Anaconda3 \ Scripts; C:\ Users \ 80LM0141IH \ AppData \Local \ Programs \ Python \ Python36 \ Scripts \; C:\ Users \ 80LM0141IH \ AppData \ Local \ Programs \ Python \ Python36 \; C:\ Users \ 80LM0141IH \ AppData \ Local \ Microsoft \ WindowsApps; G:\ MicrosoftVS代码\ bin; C:\ Users \ 80LM0141IH \ AppData \ Local \ GitHubDesktop \ bin; C:\ Users \ 80LM0141IH \ AppData \ Local \ Microsoft \ WindowsApps;; C:\ Program文件(x86)\ Graphviz2.38 \ bin; C:\ Program Files(x86)\ Graphviz2.34 \ bin;]

[shell_cmd: g++ "G:\Programming\C++\second.cpp" -o "G:\Programming\C++/second" && "G:\Programming\C++/second"] [dir: G:\Programming\C++] [path: C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\MATLAB\MATLAB Production Server\R2015a\runtime\win64;C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin;C:\Program Files\MATLAB\MATLAB Production Server\R2015a\polyspace\bin;C:\Python27\;C:\Python27\Lib\site-packages\PyQt4;C:\Program Files\Git\cmd;C:\Program Files (x86)\mingw-w64\i686-7.1.0-posix-dwarf-rt_v5-rev0\mingw32\bin;C:\Users\80LM0141IH\Anaconda3;C:\Users\80LM0141IH\Anaconda3\Library\mingw-w64\bin;C:\Users\80LM0141IH\Anaconda3\Library\usr\bin;C:\Users\80LM0141IH\Anaconda3\Library\bin;C:\Users\80LM0141IH\Anaconda3\Scripts;C:\Users\80LM0141IH\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\80LM0141IH\AppData\Local\Programs\Python\Python36\;C:\Users\80LM0141IH\AppData\Local\Microsoft\WindowsApps;G:\Microsoft VS Code\bin;C:\Users\80LM0141IH\AppData\Local\GitHubDesktop\bin;C:\Users\80LM0141IH\AppData\Local\Microsoft\WindowsApps;";C:\Program Files (x86)\Graphviz2.38\bin";C:\Program Files (x86)\Graphviz2.34\bin;]

推荐答案

在开始之前,您需要确保已安装C ++编译器并正确配置了其路径.确保可以在命令行中调用 g ++ 命令.

Before we start, you need to make sure that you have installed a C++ compiler and configured its path correctly. Make sure that you can invoke g++ command in the command line.

我从您的代码中看到,您需要标准输入中的输入.Sublime Text的控制台不能接受输入.这样也许就是问题所在.您需要在终端中运行该程序

I see from your code that you need input from the standard input. Sublime Text's console can not accept input. So that maybe that is the problem. You need to run this program in a terminal

尝试使用以下设置替换您的构建系统:

Try to replace your build system with following settings:

{
    "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c++, source.cpp, source.cc, source.cxx",

    "variants":
    [
        {
            "name": "Run in Terminal",

            "linux": {
                "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && xterm -e '${file_path}/${file_base_name} && echo && echo Press ENTER to continue && read line && exit'",
                // "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && gnome-terminal -e 'bash -c \"${file_path}/${file_base_name}&& echo && echo Press ENTER to continue && read line && exit\"'", // for gnome-terminal 
                // "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && xterm -e '${file_path}/${file_base_name}; bash'", // for xterm
                // "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && xterm -hold -e ${file_path}/${file_base_name}", // for xterm
                // "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && konsole --hold -e ${file_path}/./${file_base_name}", // for konsole

            },

            "windows":{
                "shell_cmd":   "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k  $file_base_name "
                // "shell_cmd":   "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start \"$file_base_name\" call $file_base_name"
            },

            "osx":{
                "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && xterm -e '${file_path}/${file_base_name} && echo && echo Press ENTER to continue && read line && exit'",
            },

            "shell": true,
        },
    ]
}

Ctrl + Shift + B 并选择 C ++-在终端中运行.它将在您的cmd中编译并运行该程序.

Press Ctrl + Shift + B and choose C++ - Run in Terminal. It will compile and run the program in your cmd.

我可以在我的环境中正确运行您的代码段.让我知道您是否遇到任何问题.

I can run your code snippet correctly in my environment. Let me know if you encounter any problem.

这篇关于甚至无法在Sublime Text 3中构建简单的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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