大家在看到這篇文章前,為了有一個舒適的c++IDE,一定感受到了Dev-c++的廉價感,Clion功能的多餘,VS的臃腫。他們也有自己的優點,但糟點太多,令人十分難受。而VS Code,可以取長補短。下麵的配置內容,可以讓你在刷題時,享受絲滑的動畫,體會集成終端的方便,讓你覺得Coding不再枯燥。 ...
大家在看到這篇文章前,為了有一個舒適的c++IDE,一定感受到了Dev-c++的廉價感,Clion功能的多餘,VS的臃腫。他們也有自己的優點,但糟點太多,令人十分難受。而VS Code,可以取長補短。下麵的配置內容,可以讓你在刷題時,享受絲滑的動畫,體會集成終端的方便,讓你覺得Coding不再枯燥。
Step 1
下載
- 下載VS Code
方法一:前往官網選擇適合的版本。(官網下載速度可能很慢)
方法二:快速下載鏈接。
- 安裝環境
方法一:去官網下載,具體方法自行百度。
方法二:在Dev-c++的目錄下找到 C:\Program Files (x86)\Dev-Cpp\MinGW64\bin
。(可以把其他文件夾刪掉,這個要留下,裡面的內容和方法一安裝後一樣,適合懶人)
在桌面上右鍵此電腦,屬性->高級系統設置->環境變數->Path->編輯->新建
然後把 bin
文件夾的路徑複製進去,保存。
然後打開cmd,輸入 g++
,如果和下圖中的一樣就說明成功了。
- 下載ConsolePauser
點擊鏈接下載,這個程式可以讓我們在終端運行完後自動停止,並顯示時間。
Step 2
配置
- 下載插件
在插件那一欄里搜索以下幾個插件:
必備:
1.Chinese。(中文插件)
2.C/C++。(代碼補全、語法錯誤等)
3.Code Runner。(像Clion一樣運行程式)
可以裝:
1.One Dark Pro。(好看的代碼高亮)
2.vscode-icons。(好看的圖標)
- 配置文件
在編輯器中打開一個文件夾,然後新建一個文件夾,名為 .vscode
。在這個文件夾里創建以下四個文件,並把內容複製進去:
1.c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\mingw64\\bin\\gcc.exe",//這裡要填你的mingw路徑
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
2.launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ 14 (GCC 9) ",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",//這裡要填你的mingw路徑
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++"
}
}
3.settings.json
{
"editor.cursorBlinking": "smooth",
"editor.smoothScrolling": true,
"editor.tabCompletion": "on",
"editor.fontLigatures": true,
"editor.detectIndentation": false,
"editor.insertSpaces": true,
"editor.copyWithSyntaxHighlighting": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.stickyTabStops": true,
"editor.wordBasedSuggestions": false,
"editor.cursorSmoothCaretAnimation": true,
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.rightClickBehavior": "default",
"files.autoGuessEncoding": true,
"files.autoSave": "onFocusChange",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/*.exe": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/tmp": true,
"**/node_modules": true,
"**/bower_components": true
},
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true,
"**/tmp/**": true,
"**/bower_components/**": true,
"**/dist/**": true
},
"workbench.list.smoothScrolling": true,
"workbench.editor.enablePreview": false,
"workbench.editor.untitled.hint": "hidden",
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"search.followSymlinks": false,
"window.dialogStyle": "custom",
"debug.showBreakpointsInOverviewRuler": true,
"debug.toolBarLocation": "docked",
"debug.onTaskErrors": "showErrors",
"code-runner.runInTerminal": true,
"code-runner.executorMap": {
"cpp": " cls && cd /d $dir && g++ $fullFileName -static-libgcc -std=c++11 -fexec-charset=GBK -o \"$fileNameWithoutExt.exe\" && D:\\ConsolePauser.exe $dirWithoutTrailingSlash\\$fileNameWithoutExt.exe\"",
"c": " cls && cd /d $dir && gcc $fullFileName -static-libgcc -std=c++11 -fexec-charset=GBK -o \"$fileNameWithoutExt.exe\" && D:\\ConsolePauser.exe $dirWithoutTrailingSlash\\$fileNameWithoutExt.exe\"",
},
"code-runner.saveFileBeforeRun": true,
"code-runner.customCommand": " cls",
"code-runner.respectShebang": false,
"code-runner.preserveFocus": false,
"editor.tokenColorCustomizations": {
"comments": "#399afc",
"variables": "#AAB5BB",
}
}
4.tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "D:\\Dev-Cpp\\MinGW64\\bin\\g++.exe",//這裡要填你的mingw路徑
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\Dev-Cpp\\MinGW64\\bin"//這裡要填你的mingw路徑
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活動文件",
"command": "D:\\Dev-Cpp\\MinGW64\\bin\\g++.exe",//這裡要填你的mingw路徑
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "調試器生成的任務。"
}
]
}
然後在 .vscode
同級目錄下創建文件,就可以運行啦。