Search code examples
c++sublimetext2sublimetext3sublimetext

How to run C++ in command prompt from Sublime Text?


The build systems bundled with Sublime Text run the program in the small window below the text editor pane. This is inconvenient to some as user input cannot be taken in such a case.

What is the build system script to execute the program in a separate cmd window directly from Sublime Text?


Solution

  • Go to Tools > Build System > New Build System...' and paste the following in the file:

    {
        "cmd": ["g++.exe", "-std=c++11", "-o", "$file_base_name", "$file", "&&", "start", "cmd", "/c", "$file_base_name & echo. & echo. & pause"],
        "shell": true,
        "selector": "source.c++"
    }
    

    Save the file, and while compiling your C++ code from Sublime, choose the newly created build system from Tools > Build System