skip to Main Content

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:

enter image description here

When I click this, the program is built successfully:

enter image description here

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:

enter image description here

After a few seconds, the following error message pops up:
enter image description here

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


  1. Chosen as BEST ANSWER

    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


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search