1

我在 VS Code 中使用 Code Runner 扩展来运行 C++ 代码,并且它使用了错误的终端命令来执行此操作。我在 VS Code 和 Windows 10 中使用 git-bash。

这是终端中的命令:

Douglas@LAPTOP-6BSNLLDB MINGW64 /c/path (master)
$ cd "c:\path\" && g++ HelloWorld.cpp -o HelloWorld && "c:\path\"HelloWorld
bash: cd: c:\path" && g++ HelloWorld.cpp -o HelloWorld && c:path"HelloWorld: No such file or directory

如您所见,它正在使用cd并且g++正确,但是实际运行.exe文件的命令是错误的。不应该"c:\path\HellowWorld.exe"吗?

我怎样才能改变这个?它可以与 python 一起正常工作。

如果不能,如何在 VS Code 中运行 C++ 代码?

4

3 回答 3

1

好像您使用的是 git-bash 而不是 PowerShell。

你只需要使用

"code-runner.terminalRoot": "/",

VSCode:Code Runner 扩展无法在 git bash 终端上执行代码?


将设置更改为

"code-runner.executorMap":{
 "cpp": "cd $dirWithoutTrailingSlash && g++ $fileName -o $fileNameWithoutExt && ./$fileNameWithoutExt",
}

还有c的:(我用tcc)

"code-runner.executorMap":{
 "c": "cd $dirWithoutTrailingSlash && tcc -run $fileNameWithoutExt.c",
}
于 2021-01-19T17:49:46.423 回答
0
$ cd /d "c:\path\" && g++ HelloWorld.cpp -o HelloWorld && HelloWorld
  • 或者..
$ cd /d "c:\path\" && g++ HelloWorld.cpp -o HelloWorld.exe && HelloWorld
于 2020-01-25T17:07:13.553 回答
0

wuyudi之前说的不是假的,但我认为不是

"code-runner.termnalRoot":"/",

你应该使用

"code-runner.terminalRoot":"/mnt/"

它对我来说很好,所以我希望它也适用于其他人。

于 2021-04-02T21:10:08.797 回答