在 VS Code 终端(即 Windows Powershell)中编译时遇到问题

新手上路,请多包涵

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

>  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 许可协议

阅读 1.3k
2 个回答

我遇到了同样的问题,我相信是新的 VS 代码版本 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++ 练习36.cpp -o 练习36 } ;如果 (\)?) { .\Exercise36}

对我来说,使用这个命令编译和运行也适用于新的 VS 版本。

原文由 Oscar Persson 发布,翻译遵循 CC BY-SA 4.0 许可协议

我有同样的问题

PS:

 C:\typescript_practice> tsc testclass.ts && node testclass.js

在 line:1 char:18 tsc testclass.ts && node testclass.js ~~ 标记 ‘&&’ 在此版本中不是有效的语句分隔符。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : InvalidEndOfLine

PS C:\typescript_practice> tsc testclass.ts |节点 testclass.js Sangamesh Vastrad

与下面一起工作

使用 | 而不是 && 最新的节点

原文由 Sangamesh Vastrad 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题