Visual Studio Code 介紹
Visual Studio Code 優點:
1. 可擴充 Git
2. 多樣性 - 具有不同外掛可以做使用
3. 語言種類 (可能遇到部分語言沒有外掛擴充)
4. 靈活度
5. Debugger
Extensions
Visual Studio Code 最大特點就是可以有多項化的外掛可以去做安裝到 vs code。 下方會有連結可以去點擊參閱
Extensions : https://marketplace.visualstudio.com/
我們主要安裝 C/C++ 外掛 C/C++ : https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

安裝完之後就剩下處理Debugger的問題了。
Debugger
首先,開啟VScode 開啟新的資料夾(Folder)

在新增已經新增的資料夾上新增ex01.c ,再輸程式碼。

範例如下,在第四行中,點入中斷點再來按下 F5。
#include<stdio.h>
int main(int argc, char const *argv[])
{
print("Hello world !!");
return 0;
}
會出現下圖部分,選擇有GDB部分後,會出現gcc.exe,選擇第一個。


之後會自動跑出 .vscode資料夾。要修改為"launch.json"。修改如下
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - 建置及偵錯使用中的檔案",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe", //修改成${workspaceFolder}
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true, //修改true
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", //確認MinGW路徑
"setupCommands": [
{
"description": "啟用 gdb 的美化顯示",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
修改後,在按下F5就會跑出來了。

如果跑出 "tasks.json" 設定,如下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}\\a.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
最后更新于
这有帮助吗?