在VS Code终端中编译时遇到了问题,该终端是Windows Powershell。
在VS Code终端中编译时遇到了问题,该终端是Windows Powershell。
当我右键点击运行代码,并在我的用户设置中选择在终端中运行时,我遇到了以下错误。
在第1行第63个字符: + ... "c:\Users\Josh\Documents\Programming\Learning to Program\" && g++ Exe ... + ~~ 在此版本中,“&&”不是有效的语句分隔符。 在第1行第99个字符: + ... \Learning to Program\" && 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 + 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: 无法处理参数,因为参数名“o”不明确。可能的匹配项包括:-OutVariable -OutBuffer。 在第1行第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。任何帮助将不胜感激。
在VS Code终端中无法编译的问题可能是由于新的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版本中使用这个命令编译和运行也是可以的。
在VS Code终端中编译时遇到问题,终端使用的是Windows Powershell。问题的原因是使用了无效的语句分隔符"&&",而解决方法是使用有效的语句分隔符"|"。以下是具体内容:
我遇到了同样的问题
PS:
C:\typescript_practice> tsc testclass.ts && node testclass.js
在第1行的第18个字符处:
tsc testclass.ts && node testclass.js
~~
该版本中的"&&"不是有效的语句分隔符。
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine
PS C:\typescript_practice> tsc testclass.ts | node testclass.js
Sangamesh Vastrad
下面的方法可以解决问题:
在最新的node版本中,使用"|"代替"&&"。
使用管道符号。
在"|"和"&&"或";"之间有不同的行为。我认为分号";"按顺序执行命令,相当于"&&"。