简体   繁体   English

VSCode Run C/C++ File 尝试在 WSL 集成终端中运行编译后的程序,而不是 CMD

[英]VSCode Run C/C++ File attempts to run the compiled program in WSL integrated terminal instead of CMD

I've got a strange problem occurring when attempting to run a C++ program on VSCode.尝试在 VSCode 上运行 C++ 程序时出现了一个奇怪的问题。 For examples sake, let's say I have the following main.cpp为了举例,假设我有以下 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:然后我 go 使用右上角的Run C/C++ File按钮编译和运行程序:

在此处输入图像描述

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.然而,VSCode 然后尝试在 WSL 集成终端而不是 CMD 中运行构建的可执行文件,尽管 CMD 是我的默认集成终端。 This obviously throws an error:这显然会引发错误:

在此处输入图像描述

After a few seconds, the following error message pops up:几秒钟后,弹出以下错误消息: 在此处输入图像描述

My launch.json looks like this for reference:我的 launch.json 是这样的,供参考:

{
    // 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:)谢谢:)

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".如果未打开,请按Ctrl + `打开内置终端,然后单击终端右上角“+”符号旁边的下拉菜单,然后单击“配置终端设置”。 In the tab that opens, set Terminal › External: Windows Exec to C:\Windows\System32\cmd.exe在打开的选项卡中,将Terminal › External: Windows Exec设置为 C:\Windows\System32\cmd.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.如果它仍然没有按预期工作,它可能是一个扩展,正如安东尼在评论中所说的那样。

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"出于某种奇怪的原因,在我的用户设置 (JSON) 的顶部,我有"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe"

I simply deleted the line and now everything is fine我只是删除了该行,现在一切都很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM