目錄
本文資源:https://lanzous.com/icwp57g
所需程式
檔案夾結構
各檔案内容
launch.json (//---***要注意的點!)
tasks.json (//---***要注意的點!)
test_c.c——C檔案
test_cpp.cpp——Cpp檔案
測試結果
C的——(調試控制台不能列印printf()函數的内容)
Cpp的——(調試控制台能列印cout()函數的内容)
常見錯誤
調試檔案選擇錯誤
調試器選擇錯誤
Finish!
所需程式
VS Code的
電腦的(我用MinGW,配置一下環境變量)
檔案夾結構
.vscode——配置檔案夾
test_c.c/test_cpp.cpp——測試檔案
各檔案内容
launch.json (//---***要注意的點!)
{
"version": "0.2.0",
"configurations": [
//-------------------------gdb-c這是C檔案的-----------------------------
{
"name": "gdb-c",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
//***********************************************圖二位址
"miDebuggerPath": "C:\\APP\\MinGW\\bin\\gdb.exe",
//***********************************************
"setupCommands": [
{
"description": "為 gdb 啟用整齊列印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
//********************雙引号裡面的内容和tasks.json的label内容要一樣
"preLaunchTask": "gcc"
//********************
},
//-------------------------gdb-cpp這是Cpp檔案的---------------------
{
"name": "gdb-cpp",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
//***********************************************圖二位址
"miDebuggerPath": "C:\\APP\\MinGW\\bin\\gdb.exe",
//***********************************************
"setupCommands": [
{
"description": "為 gdb 啟用整齊列印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
//********************雙引号裡面的内容和tasks.json的label内容要一樣
"preLaunchTask": "g++"
//********************
}
]
}
tasks.json (//---***要注意的點!)
{
"version": "2.0.0",
"tasks": [
//-------------------g++這是cpp檔案的
{
"type": "shell",
//****************************************圖二位址
"label": "g++",
"command": "C:\\APP\\MinGW\\bin\\g++.exe",
//****************************************
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
//**************************到bin就好
"cwd": "C:\\APP\\MinGW\\bin"
//**************************
},
"problemMatcher": [
"$gcc"
]
},
//-------------------gcc這是c檔案的
{
"type": "shell",
//****************************************圖二位址
"label": "gcc",
"command": "C:\\APP\\MinGW\\bin\\gcc.exe",
//****************************************
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
//**************************到bin就好
"cwd": "C:\\APP\\MinGW\\bin"
//**************************到bin就好
},
"problemMatcher": [
"$gcc"
]
}
]
}
test_c.c——C檔案
#include <stdio.h>
int main()
{
int x, y;
x=0;
y=3;
printf("x+y=%d \n",(x+y));
printf("Hello C!");
return 0;
}
test_cpp.cpp——Cpp檔案
#include <iostream>
using namespace std;
int main()
{
int x,y;
x=0;
y=3;
cout << x+y << endl;
cout << "hello" << endl;
printf("Hello C!");
return 0;
}
測試結果
C的——(調試控制台不能列印printf()函數的内容)
Cpp的——(調試控制台能列印cout()函數的内容)
常見錯誤
調試檔案選擇錯誤
調試器選擇錯誤
Finish!
如有錯誤,請指正!技術因交流而強大!