【发布时间】:2021-10-28 04:03:07
【问题描述】:
我想开始学习 C++,但我注意到在 VSCode 中调试它有点烦人。 在教程页面上,它说我应该通过开发人员控制台启动它。 由于我不想这样做,所以我搜索了一下,最终得到了这个解决方案:
tasks.json:
{
"version": "2.0.0",
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": [
"/C",
"\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat\"",
"&&"
]
}
}
},
"tasks": [
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json:
{
"version": "2.0.0",
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": [
"/C",
"\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat\"",
"&&"
]
}
}
},
"configurations": [
{
"name": "Debug",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "cl.exe build active file"
}
]
}
这确实有效,但前提是路径中没有空格。 如果有,它会给出这个错误:
Der Befehl "C:/Program" ist entweder falsch geschrieben oder konnte nicht gefunden werden.
(对不起德语,这里是翻译: 命令“C:/Program”要么输入不正确,要么不存在。)
我试图解决这个问题,但我只是没有得到问题。 任何帮助表示赞赏!
【问题讨论】:
-
由于stackoverflow是English-only platform,你能翻译一下你的错误吗?
-
在程序中使用引号,就像在 args 中使用它们一样。
-
@S.M.你是什么意思?
-
您不需要在
args字符串中加上引号(它们可能是您的问题的原因)。既然你已经安装了视觉工作室,为什么不直接使用它呢?设置起来要容易得多。如果你真的想使用 vs-code 试试documentation -
@AlanBirtles 你的意思是在 launch.json 中?那没有用...至于VS,我可以,但是如果您知道我的意思,我只是觉得它有点“沉重”...而且切换操作系统和拥有熟悉的环境也更容易。 (Linux afaik 上没有 VS。)
标签: c++ debugging visual-studio-code