本帖最后由 FK二十一 于 2022-4-4 16:31 编辑
你这个是根本没有配置好吧。。。vscode里面要跑什么代码都是要配置文件的,一般是launch.json ,tasks.json 和 settings.json三个文件都要配(可以在 查看->命令面板 里面找)。一般一个文件夹(也就是项目)要配这三个文件。 如果你的项目跑的是相同的代码,比如C/C++(这两个相同的配置都能用),你就配一个.vscode(里面有上述的三个配置文件)就行。你可以搜一下网上的配置,多操作探索几次。下面我把我的三个配置发一下,分别是launch.json,settings.json 和 tasks.json。对了,还要设置环境变量 的,这些不会的话 b站查查视频,跟着操作几遍就熟练了。文字描述你不好懂的。
注意看一下编译器的地址,要你自己电脑上的地址。
1.
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/download/MinGW/bin/gdb.exe", // 这里修改GDB路径为安装的mingw64的bin下的gdb.exe路径
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}]
}
2.
{
"code-runner.saveFileBeforeRun": true, // run code前保存
"editor.cursorSmoothCaretAnimation": true, // 移动光标时变得平滑
"vim.autoSwitchInputMethod.enable": true,
"files.associations": {
"*.json": "json",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}
3.
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "g++",
"args": [
"-ggdb",
"\"${file}\"",
"--std=c++11",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
]
}
}
]
}