向c++程序传递参数以便在VSCode中调试

visual studio code - Passing arguments to C++ programme for debugging in VSCode

本文关键字:VSCode 调试 参数 c++ 程序      更新时间:2023-10-16

我想调试VSCode中的c++项目(在Mac上,使用GDB或LLDB)。程序本身接受命令行参数,如

./prog -input cf file_x.txt

当在命令行上启动GDB中的调试会话时,这很好。

在VSCode中,我试图使launch.json读成这样(只显示相关行):

"program": "${workspaceRoot}/build/prog",
            "args": [
              "-input cf",
               "path_to/file_x.txt"
            ]

这样,我在输出中得到@"Unknown option: "-input cf"rn",并且未调试该过程;或者,我只尝试了一个参数,像这样:

"program": "${workspaceRoot}/build/prog",
            "args": [
              "-input cf path_to/file_x.txt"
            ]

产生相同的消息。我错过了什么重要的事情吗?

像这样试试

"program": "${workspaceRoot}/build/prog",
            "args": [
              "-input",
              "cf",
              "path_to/file_x.txt"
            ]

2022年,我只做:

 "args": [
    "your_arg1",
    "your_arg2"
 ]

(在启动。Json)