Reputation: 43
First i'll tell you that -I am new to coding
I am using vs code for learning c++ and it does not spawn a debugger like dev c++ or codeblocks. I saw some videos in which we have to edit the json files which is pretty complicated for beginners.Can anyone guide me how to to do this simply? And also that whenever I create a new cpp file do I have to edit those files again?
Upvotes: 1
Views: 132
Reputation: 1175
If you are using GCC compiler (and I recommend you do, otherwise stick to VS) you can reference this guide which is quite good: https://code.visualstudio.com/docs/cpp/config-mingw
Creating аnd editing launch.json fils is quite easy. However, it might seem overwhelming at the beginning. Just use the following code and modify the name of your executable and location of your debugger (which is the location where you installed MinGW)
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
About other options, you can refer to the guide or other resources, but this code can be used as-is, except the abovementioned executable name program
and debugger path miDebuggerPath
.
You only need to reference .cpp file containing main()
. Other files are assumed by the compiler if you used #include
in your source file containing main()
Upvotes: 3