Nathan
Nathan

Reputation: 141

How do I build/debug the current open .cpp file in Visual Studio Code?

Is there a way to set up Visual Studio Code with a debug task that compiles and debugs the current open .cpp file? I'm on macOS Sierra 10.12.6.

The standard documentation explains creating a task that compiles a specific .cpp file to a.out and modifying the launch.json to run that as a preLaunchTask, but then I have to create a new task for each .cpp file I create. It gets a bit tedious as I'm learning C++ and writing many small example programs.

Somebody asked a similar question here but this solution only seems to compile the first .cpp it encounters. If it compiled all .cpp files, it would probably help for me.

How do I set up VSCode to compile C++ code?

Upvotes: 1

Views: 2393

Answers (1)

ifconfig
ifconfig

Reputation: 6832

You can do something like the answer to this SO Question.

One way to avoid creating separate build tasks for each file (as long as the language you are using is the same) is to use the ${file} keyword instead of the filename in the build task in tasks.json, which will build the file you currently have open in VS Code.

Upvotes: 3

Related Questions