📅  最后修改于: 2023-12-03 15:13:53.810000             🧑  作者: Mango
Sublime Text is a popular text editor used by many programmers. It is highly extensible and customizable, allowing users to tailor the editor to their individual use cases. One of the key features of Sublime is its build system, which allows users to execute code and view output within the editor itself.
When it comes to C++ development, Sublime supports a range of build systems for compiling and running code. In this article, we will focus on the C++ 14 build system for Sublime on Windows.
To use the C++ 14 build system for Sublime on Windows, you will need to first install the MinGW-w64 toolchain. This toolchain provides the GCC compiler and other necessary tools for compiling C++ code.
To install MinGW-w64, follow these steps:
Download the latest version of MinGW-w64 from the official website: https://sourceforge.net/projects/mingw-w64/
Run the installer and select the following options:
Select an installation directory of your choice.
Click "Install" to begin the installation process.
Once MinGW-w64 is installed, you can set up the C++ 14 build system in Sublime.
To set up the C++ 14 build system in Sublime, follow these steps:
Open Sublime Text and create a new file.
Copy and paste the following code into the file:
{
"cmd": ["g++", "-std=c++14", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"cmd": ["start", "${file_path}/${file_base_name}.exe"]
}
]
}
Save the file with the name "C++ 14.sublime-build" in the following directory:
%USERPROFILE%\AppData\Roaming\Sublime Text 3\Packages\User
Note: If you are using a different version of Sublime, replace "Sublime Text 3" with the appropriate version number.
Restart Sublime Text to apply the changes.
You should now be able to use the C++ 14 build system to compile and run C++ code in Sublime.
To use the C++ 14 build system in Sublime, follow these steps:
Open a C++ file in Sublime.
Press Ctrl + B
to build the file.
If there are no errors, a new window will open showing the output of the program.
Note: If there are errors, the output will show the error messages and their locations in the code.
To run the program, select the "Run" variant from the build menu (Tools -> Build With
).
Note: If the program takes input, you can provide it in the output window before running the program.
The C++ 14 build system for Sublime on Windows provides a fast and convenient way to compile and run C++ code within the editor. By following the steps outlined in this article, you should be able to set up the build system and start developing in no time. Happy coding!