How to add switches as in shutdown.exe -s -f | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to add switches as in shutdown.exe -s -f

When I create a C++ program, I get an exe as binary file. I wish to enhance it with parameters like -s -f -r or -onboot etc.

27th Jul 2018, 3:10 AM
Core i9
Core i9 - avatar
1 Answer
+ 4
Change the signature of your main function to incorporate your program to take command line arguments like; int main(int argc, char* argv[]) {...} where argc is the count of command line arguments the user has input at the command line and argv is an array of pointers to the commands line arguments input. Then you need to write the code to loop over the argv array an handle the command(s) input etc.
27th Jul 2018, 4:29 AM
ChaoticDawg
ChaoticDawg - avatar