Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run C++ program in Powershell, just like CMD?

Like in CMD, to run a C++ program, I use the command g++ filename.cpp, then I run it using the command a.exe, which opens the output in the CMD itself. How to do such thing using a PowerShell? I am unable to open the file by simple command as a.exe. Am I doing it the wrong way?

like image 880
Vrishank Gupta Avatar asked Dec 09 '25 13:12

Vrishank Gupta


2 Answers

It is a best practice to use the invocation operator and to quote the command.

& ".\a.exe" p1 p2 p3

PowerShell will also allow the use of / as the path separator.

& "./a.exe" p1 p2 p3 "p4 with space"
like image 53
lit Avatar answered Dec 11 '25 03:12

lit


by running g++ filename.cpp on PowerShell it generates a.exe file by default on running a.exe it gives an error

so follow these commands

g++ filename.cpp -o filename.exe

filename.exe

like image 44
Shashidhar Kudari Avatar answered Dec 11 '25 03:12

Shashidhar Kudari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!