I'm working on a project that needs to be run with either of the following commands:
./project.exe -Stack < [filename]
./project.exe -Queue < [filename]
I am wondering why there is a - in front of both Stack and Queue and why the filename is preceded by < and is in brackets.
The purpose of this format is to tell the program to either run using a stack class or run using a queue class. I will also need to extract the information from the text file mentioned in the command line.
I am familiar with general command line arguments and how to use them, but I have never seen this notation before and can't find any clear explanations.
The dash for the options are simply a common convention. Usually with modern command-line programs one uses double-dash for so-called long options (like e.g. --stack) and single dash for short options (e.g. -s).
Many existing argument parsers, like the Linux getopt_long function, actually requires the single or double dashes for short and long options to be recognized as such.
The < is file redirection. It tells the shell to redirect the programs standard input from the file. Inside the program you can read from standard input (std::cin) and it will be automatically reading from the file. This redirection is handled entirely by the shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With