用vscode打開工程目錄,
首先安裝這幾個插件:C/C++,C/C++ Compile Run, Code Runner
然后ctrl + shift + p ,
搜索c/c++ 選擇 Edit Configuration(Json),
這時工程目錄應該已經生成一個.vscode文件夾,和一個c_cpp_properties.json 文件,
再新增這幾個文件,launch.json, tasks.json, setting.json
對應修改文件內容如下:
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\Program Files\mingw64\include" // 這里對應自己本地的c編譯器的目錄
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\Program Files\mingw64\bin\gcc.exe", //同樣對應本機的,下面的不用動
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
============
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe",
"type": "cppdbg",
"request": "launch",
// "program": "{fileDirname}\
{workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\Program Files\mingw64\bin\gdb.exe", // 對應即可
"setupCommands": [
{
"description": "gdb print",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask":"gcc.exe build active file"
}
]
}
==========
tasks.json:
{
"version": "2.0.0",
"command": "gcc",
"args": [
"-g",
"{fileBasenameNoExtension}.exe"
],
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command":"C:\Program Files\mingw64\bin\gcc.exe", // 對應本地
"args": [
"-g",
"{fileDirname}\
gcc"
],
"group": "build"
}
]
}
=============
setting.json:
{
"code-runner.runInterminal":true
}
最后設置:
左下角--settings--run in terminal 選項 勾上,重啟vscode即可,支持在控制臺輸入scanf
mac 的同樣步驟,但是無法使用terminal,有時間再看
mac 配置:
大致相同:如果是使用clang 那就換一下編譯器的地址
c_cpp_properties.json:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "gcc",
"type": "shell",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher":[
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
然后是插件:code-runner中打開 run interminal