Sublime installation tutorial and configure C++ environment

Sublime installation tutorial and configure C++ environment

Preface

I recently reinstalled my computer and checked a lot of information when configuring sublime. I really wasted a lot of time. I thought it would be better to write a blog and record it. It is not only convenient for myself but also for everyone. Because of the current need to program C++ related programs, it is still necessary to configure a C++ environment.

Download sublime

First, give the download website. The download in the built-in browser of windows is relatively fast, just a few seconds. In Chromn, it takes half an hour to an hour, and it even gets stuck at 0. This is still not clear.
Link: After downloading the link
Insert picture description here
Insert picture description here
, unzip it and use it.

Configure C++ environment

The next step is to configure the C++ environment variables . In this process, you can choose to install a MinGW directly (many people have used codeblocks or Dev-C++ when writing c, if you have installed codeblocks or Dev-C++, you don’t need to download MinGW),My suggestion is to install a Dev-C++ directly, Simple, no need to point various things, just go to Tencent Software Center to download, there will be corresponding g++ and the like.
After the download is complete, we need to click on my computer, enter the environment variable settings in the advanced settings, and add the Dev-C++ bin directory to the path in the system variables (directly right-click on the desktop to open the file location in Dev, as shown below)
Insert picture description here
Copy the address , Paste it into the path and click OK.
Go back to the desktop and use windows+R , enter cmd
and then enter g++ -v in it . If something similar appears in the figure below, it means ok.
Insert picture description here
Everything is ok to enter sublime.
In the sublime toolbar, select Tools -> Build System -> New Build System

Add the following code, save it as "C++.sublime-build", and set the path to the default path.

{
    
    
	"encoding": "utf-8",
	"working_dir": "$file_path",
	"shell_cmd": "g++ -Wall -std=c++0x \"$file_name\" -o \"$file_base_name\"",
	"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
	"selector": "source.cpp",

	"variants": 
	[
		{
    
       
			"name": "Run",
			"shell_cmd": "g++ -Wall -std=c++0x  \"$file\" -o \"$file_base_name\" && \"${file_path}/${file_base_name}\""
		},
		{
    
       
			"name": "RunInCmd",
			"shell_cmd": "g++ -Wall -std=c++0x  \"$file\" -o \"$file_base_name\" && start cmd /c \"\"${file_path}/${file_base_name}\" & pause \""
		}
	]
}

After saving, you will see the C++ build system under tool -> build system of sublime, select it. Press the key combination Ctrl + Shift + b to pop up the compilation command selection window, select RunInCmd to compile.
Insert picture description here
The difference between C++ and C+±RunInCmd is that C++ only compiles and does not execute; while C++ -RunInCmd is executed directly in the console after compilation.
Now, your sublime can compile C++ code, if it works, please give me a thumbs up!

Guess you like

Origin blog.csdn.net/Freedom_cao/article/details/107137805