1

In macOS whenever I compile and execute my code I use g++ name.cpp && ./a.out

but in Windows it doesn't work for compile and run i use

g++ name.cpp
./a.exe

I'm using command prompt. g++ name.cpp && ./a.exe doesn't work. But i want to use a single line command like i used to do in macOS

  • 3
    Does this answer your question? [How do I run two commands in one line in Windows CMD?](https://stackoverflow.com/questions/8055371/how-do-i-run-two-commands-in-one-line-in-windows-cmd) – blami Sep 03 '20 at 15:24
  • 2
    Specify whether you are using `cmd` or Powershell. Specify how "it doesn't work"; what error do you get?? – underscore_d Sep 03 '20 at 15:40

2 Answers2

3

In Windows, backslash (or yen mark on some font) is used as separator of directory.

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

worked on Command Prompt (but not on PowerShell).

MikeCAT
  • 73,922
  • 11
  • 45
  • 70
1
  1. Separate the two different commands using &&.
  2. For invoking the application it depends on your terminal:
    a - you have to use '\' not '/' when using powershell: (.\a.exe)
    b - just call the executable when using the ancient dos terminal: (a.exe)
Yksisarvinen
  • 18,008
  • 2
  • 24
  • 52
C.J.
  • 15,637
  • 9
  • 61
  • 77