How to compile and run c++ programs in Sublime Text 3

pull

I went to Qingbei Academy and felt that I was having a good time. I didn’t learn much about the algorithm, but I learned a lot about front-end and crawler.


Then I found out that there is an editor called sublime text 3. I don't know if it is easy to use or not, so I looked at it and decided to use it in the future.

Then the trouble came out,

What's the use of only editing but not compiling, and console commands are too troublesome, so I might as well go to Dev-cpp.

Then I spent a bit of time on the Internet to find a tutorial on configuring sublime

It took me about half an hour to figure it out because my brain was stupid.

Here's the thing


 

First, make sure that the g++ compiler is installed in the system, and then configure the environment variables.

There are many tutorials on the Internet, I don't need to spend more time.

The effect of successfully configuring environment variables is as follows:

Enter "g++" in cmd, press Enter, if the content shown in the picture appears, it proves that the configuration is complete

Then you can open sublime to start the operation

First find Tools -> Build System -> New Build System… on the (English) toolbar to open

Enter the following in the open file

 1 {
 2     "encoding": "utf-8",
 3     "working_dir": "$file_path",
 4     "shell_cmd": "g++ -Wall -std=c++11 \"$file_name\" -o \"$file_base_name\"",
 5     "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
 6     "selector": "source.c++",
 7  
 8     "variants": 
 9     [
10         {    
11         "name": "Run",
12             "shell_cmd": "g++ -Wall \"$file\" -o \"$file_base_name\" && start cmd /c \"\"${file_path}/${file_base_name}\" & pause\""
13         }
14     ]
15 }

Then Ctrl + S to save, just change the file name or whatever qwq

Then your sublime will compile

The shortcut key for compilation (not fast) is Ctrl + Shift + B

Select the file you just configured in the window to compile

-run is to compile and run, no big problem


in addition

You can also debug the program (gdb) in the same way

The settings of the shortcut key adjustment can be found on Baidu

<end>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326630372&siteId=291194637