I’ve got a strange problem occurring when attempting to run a C++ program on VSCode. For examples sake, let’s say I have the following main.cpp
#include <iostream>
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}
I then go to compile and run the program using the Run C/C++ File
button in the top right:
When I click this, the program is built successfully:
However, VSCode then attempts to run the built executable in the WSL integrated terminal instead of CMD, despite CMD being my default integrated terminal. This obviously throws an error:
After a few seconds, the following error message pops up:
My launch.json looks like this for reference:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
]
}
I’m not sure what to do to fix this, so any help would be greatly appreciated. Thank you 🙂
2
Answers
I finally found the issue to my problem. For some strange reason, at the top of my User Settings (JSON), I had
"terminal.integrated.shell.windows": "C:\WINDOWS\System32\wsl.exe"
I simply deleted the line and now everything is fine
Press Ctrl + ` to open the inbuilt terminal if it’s not open, then click on the dropdown next to the "+" dymbol at the top right corner of the terminal, and click on "Configure Terminal Settings". In the tab that opens, set Terminal › External: Windows Exec to C:WindowsSystem32cmd.exe
Should do the trick. If it still doesn’t work as expected, it might be an extension doing it, as Anthony said in the comments.