1、安裝vscode(版本1.27)
https://code.visualstudio.com/ 下載安裝vscode。
2、安裝c/c++擴(kuò)展。
3、安裝編譯工具mingw-w64,http://www.mingw-w64.org/doku.php/download
配置環(huán)境變量,以WIN10為例 ,此電腦-屬性-高級(jí)系統(tǒng)設(shè)置-環(huán)境變量-系統(tǒng)變量-path-添加一條D:Program Filesmingw-w64i686-8.1.0-posix-dwarf-rt_v6-rev0mingw32bin(你安裝編譯工具路徑)
配置前
配置后
-ps:如果開著vscode配置環(huán)境變量,配置完要關(guān)掉vscode重開一次。
4、配置文件launch.json,task.json。
新建文件hello.cpp,
按F5彈出選擇環(huán)境,配置launch.json
點(diǎn)擊進(jìn)去,configurations:里內(nèi)容如下:
{ "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "enter program name, for example ${workspaceFolder}/a.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "/path/to/gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }
修改成如下:
{ "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/a.exe",//這里刪除前面那里的enter program name, for example "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:\Program Files\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\gdb.exe", //修改為你安裝mingw32的路徑 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build hello",//task.json里面的名字 }
回到hello.cpp按F5彈出報(bào)錯(cuò)框,選配置任務(wù)。
點(diǎn)擊,然后選Others,出現(xiàn)task.json,如下:
"version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "echo Hello" } ]
修改如下:
"version": "2.0.0", "tasks": [ { "label": "build hello", "type": "shell", "command": "g++", "args": [ "-g", "hello.cpp", ], "group":{ "kind": "build", "isDefault": true } } ]
注意:如果是win32程序(窗口界面),args內(nèi)加上"-mwindows"。
回到hello.cpp文件,按F5。成功運(yùn)行編譯。
5、還有就是發(fā)現(xiàn)中文控制臺(tái)顯示亂碼。
只要點(diǎn)擊右下角utf-8。
點(diǎn)擊使用編碼保存,選GBK,然后按F5運(yùn)行。
PHP中文網(wǎng),有大量免費(fèi)vscode入門教程,歡迎大家學(xué)習(xí)!