c++visual-studio-codecmdline-args

Passing arguments to C++ programme for debugging in VSCode


I want to debug a C++ project in VSCode (on a Mac, using either GDB or LLDB). The program itself takes command line arguments like

./prog -input cf file_x.txt

This works fine when starting a debugging session in GDB on the command line.

In VSCode, I tried to adapt launch.json to read like this (only relevant lines shown):

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

With this, I get @"Unknown option: \"-input cf\"\r\n" in the output and the process is not debugged; alternatively, I tried only one argument like so:

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

resulting in the same message. Have I missed something important?


Solution

  • Try it like this

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