当我右键单击运行代码并在我的用户设置中的终端中运行时,我收到这些错误。
> 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 > > ``` 直到今天我一直在编译,我做了一些谷歌搜索并开始在终端中输入我自己的命令,而不仅仅是运行代码。 我开始用 `&&` 替换 `-and` 并遇到不同的问题。这就是命令现在的样子。
“c:\Users\Josh\Documents\Programming\Learning to Program\” -and g++ Exercise36.cpp -o Exercise36 -and “c:\Users\Josh\Documents\Programming\Learning to Program\“Exercise36
”`
这是我得到的错误。
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
我正在使用 GNU 开源编译器,这是我在编译时遇到的第一个问题,因为我意识到你必须在编译之前保存。我正在运行一个简单的字符串,它将从 C++ Primer 程序从终端读取的字符串中的所有字符更改为 X。任何帮助,将不胜感激。
原文由 XPMJosh 发布,翻译遵循 CC BY-SA 4.0 许可协议
我遇到了同样的问题,我相信是新的 VS 代码版本 1.35 引起的。我尝试降级到 1.34 并再次编译和运行 c++。
旧版本似乎使用不同的命令运行代码:
在您的情况下,它看起来像:
对我来说,使用这个命令编译和运行也适用于新的 VS 版本。