用vscode打開(kāi)工程目錄猛蔽,
首先安裝這幾個(gè)插件:C/C++,C/C++ Compile Run, Code Runner
然后ctrl + shift + p 聘芜,
搜索c/c++ 選擇 Edit Configuration(Json)梅掠,
這時(shí)工程目錄應(yīng)該已經(jīng)生成一個(gè).vscode文件夾福铅,和一個(gè)c_cpp_properties.json 文件嘁扼,
再新增這幾個(gè)文件帚桩,launch.json, tasks.json, setting.json
對(duì)應(yīng)修改文件內(nèi)容如下:
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\Program Files\mingw64\include" // 這里對(duì)應(yīng)自己本地的c編譯器的目錄
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\Program Files\mingw64\bin\gcc.exe", //同樣對(duì)應(yīng)本機(jī)的甸箱,下面的不用動(dòng)
"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", // 對(duì)應(yīng)即可
"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", // 對(duì)應(yīng)本地
"args": [
"-g",
"{fileDirname}\gcc"
],
"group": "build"
}
]
}
=============
setting.json:
{
"code-runner.runInterminal":true
}
最后設(shè)置:
左下角--settings--run in terminal 選項(xiàng) 勾上芦昔,重啟vscode即可,支持在控制臺(tái)輸入scanf
mac 的同樣步驟蛛砰,但是無(wú)法使用terminal,有時(shí)間再看
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中打開(kāi) run interminal