g++ 可以被 cmd 识别,但不能被 vs code 识别

g++ is recognized by cmd but not by vs code

我正在尝试在我的 visual studio 代码中设置 c/c++ 环境。我已经安装了mingw并设置了bin文件夹的环境变量。但是在 运行 vs code 中的代码,它显示以下错误:

g++ : The term 'g++' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:40 cd "e:\vsCodes\Cpp Codes" ; if ($?) { g++ threen1.cpp -o threen1 } ; ... CategoryInfo : ObjectNotFound: (g++:String) [], CommandNotFound Exception FullyQualifiedErrorId : CommandNotFoundException

但是当我输入 g++ --version 时,命令提示符显示以下消息:

g++ (tdm64-1) 10.3.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我已尝试按照 中的答案解决问题。

您正在使用 powershell 终端,如果您不知道什么是 powershell 或者您不需要 powershell,我建议您使用 运行 命令提示符终端 (cmd)。它在终端菜单中可用:

在 powershell 中,您可以验证 g++PATH 运行 中执行此命令 echo $env:path,它与 echo %PATH%

等效