【问题标题】:Compile and run at the same time with a single line command in windows [duplicate]在Windows中使用单行命令同时编译和运行[重复]
【发布时间】:2020-12-22 21:00:53
【问题描述】:

在 macOS 中,每当我编译和执行我使用的代码时 g++ name.cpp && ./a.out

但在 Windows 中它不适用于我使用的编译和运行

g++ name.cpp
./a.exe

我正在使用命令提示符。 g++ name.cpp && ./a.exe 不起作用。 但我想像以前在 macOS 中那样使用单行命令

【问题讨论】:

标签: c++ c


【解决方案1】:
  1. 使用 && 分隔两个不同的命令。
  2. 调用应用程序取决于您的终端:
    a - 使用 powershell 时必须使用 '\' 而不是 '/': (.\a.exe)
    b - 使用古老的 dos 终端时只需调用可执行文件:(a.exe)

【讨论】:

    【解决方案2】:

    在 Windows 中,反斜杠(或某些字体上的日元标记)用作目录的分隔符。

    g++ name.cpp && .\a.exe
    

    在命令提示符上工作(但不在 PowerShell 上)。

    【讨论】:

    • && 不起作用(& 不允许)
    • @SanskarJaiswal 这个works for me.
    • 我什至没有注意到我在使用 powershell 我以为我在使用 cmd 。然后我在 vs-code 中将其更改为 cmd ...非常感谢
    猜你喜欢
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 2013-03-04
    相关资源
    最近更新 更多