用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
网友评论