在 VS Code 终端(Windows Powershell)中编译时遇到问题 [英] Having trouble compiling in VS Code terminal, which is Windows Powershell

查看:52
本文介绍了在 VS Code 终端(Windows Powershell)中编译时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我右键单击运行代码"并在我的用户设置中的终端中运行时,我收到这些错误.

<块引用>

在行:1 字符:63+ ... "c:\Users\Josh\Documents\Programming\Learning to Program\" &&g++ exe ...+ ~~令牌&&"在此版本中不是有效的语句分隔符.在行:1 字符:99+ ... \学习编程\" && g++ Exercise36.cpp -o Exercise36 && "c:\Use ...+ ~~令牌&&"在此版本中不是有效的语句分隔符.在行:1 字符:102+ ... ercise36 &&"c:\Users\Josh\Documents\Programming\Learning to Program\ ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~表达式只能作为管道的第一个元素.在行:1 个字符:160+ ... "c:\Users\Josh\Documents\Programming\Learning to Program\"Exercise36+ ~~~~~~~~~~表达式或语句中出现意外标记Exercise36".+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException+ FullQualifiedErrorId : InvalidEndOfLine

直到今天,我一直在编译,我做了一些谷歌搜索并开始在终端中输入我自己的命令,而不仅仅是运行代码.

我开始用 -and 替换 && 并遇到不同的问题.这就是命令现在的样子.

"c:\Users\Josh\Documents\Programming\Learning to Program\" -and g++ Exercise36.cpp -o Exercise36 -and "c:\Users\Josh\Documents\Programming\Learning to Program\练习36

这是我得到的错误.

<块引用>

Set-Location:无法处理参数,因为参数名称o"不明确.可能的匹配项包括:-OutVariable -OutBuffer.在行:1 字符:87+ ... \Programming\Learning to Program\" - 和 g++ Exercise36.cpp -o 练习 ...+ ~~+ CategoryInfo : InvalidArgument: (:) [Set-Location], ParameterBindingException+ FullQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.SetLocationCommand

我使用的是 GNU 开源编译器,这是我在编译时遇到的第一个问题,因为我意识到必须在编译之前进行保存.我正在运行一个简单的字符串,它将从 C++ Primer 程序的终端读取的字符串中的所有字符更改为 X.任何帮助将不胜感激.

解决方案

我也遇到了同样的问题,我认为是新的 VS Code 1.35 版本引起的.我尝试降级到 1.34 并再次编译和运行 c++.

旧版本似乎使用不同的命令运行代码:

<块引用>

"cd $dir ; if ($?) { g++ $fileName -o $fileNameWithoutExt } ; if ($?) { .\\$fileNameWithoutExt}"

在您的情况下,它看起来像:

<块引用>

cd "c:\Users\Josh\Documents\Programming\Learning to Program\" ;if ($?) { g++ Exercise36.cpp -o Exercise36 } ;if ($?) { .\Exercise36}

对我来说,使用这个命令在新的 VS 版本中编译和运行也是有效的.

When I right click Run code, and have run in terminal on in my user settings I get these errors.

At line:1 char:63
+ ... "c:\Users\Josh\Documents\Programming\Learning to Program\" && g++ Exe ...
+                                                                ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:99
+ ... \Learning to Program\" && g++ Exercise36.cpp -o Exercise36 && "c:\Use ...
+                                                                ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:102
+ ... ercise36 && "c:\Users\Josh\Documents\Programming\Learning to Program\ ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
At line:1 char:160
+ ...  "c:\Users\Josh\Documents\Programming\Learning to Program\"Exercise36
+                                                                ~~~~~~~~~~
Unexpected token 'Exercise36' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidEndOfLine

I have been compiling fine up until today, and I did some googling and started typing my own commands into the terminal instead of just running code.

I started replacing the && with -and and get a different problem. This is what the command looks like now.

"c:\Users\Josh\Documents\Programming\Learning to Program\" -and g++ Exercise36.cpp -o Exercise36 -and "c:\Users\Josh\Documents\Programming\Learning to Program\"Exercise36

This is the error I get.

Set-Location : Parameter cannot be processed because the parameter name 'o' is ambiguous. Possible matches include: -OutVariable -OutBuffer.
At line:1 char:87
+ ... \Programming\Learning to Program\" -and g++ Exercise36.cpp -o Exercis ...
+                                                                ~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Location], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.SetLocationCommand

I am using the GNU open source compiler, this is the first issue I have had with compiling since I realized you have to save before you compile. I am running a simple string that changes all the characters to X from a string that is read from terminal from C++ Primer program. Any help would be appreciated.

解决方案

I had the same problem, I believe it is caused by the new VS code version 1.35. I tried downgrading to 1.34 and compiling and running c++ worked again.

The old version seems to run the code with a different command:

"cd $dir ; if ($?) { g++ $fileName -o $fileNameWithoutExt } ; if ($?) { .\\$fileNameWithoutExt}"

in your case it would look like:

cd "c:\Users\Josh\Documents\Programming\Learning to Program\" ; if ($?) { g++ Exercise36.cpp -o Exercise36 } ; if ($?) { .\Exercise36}

For me using this comand compiling and running works in the new VS version aswell.

这篇关于在 VS Code 终端(Windows Powershell)中编译时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆