I know that to use command line arguments, I have to do this.
int main(int argc, char* argv[])
Now most of the documentation i read about taking in command line arguments explain the situation, something like this:
Command-line arguments are given after the name of a program in command-line operating systems like DOS or Linux, and are passed in to the program from the operating system.
So the only way i know to open my program, is to open it normally like i would do, either start debugging or open the exe file
Now here it seems that, to use command line arguments the program has to be opened differently, Using the Command-Line (DOS/Command Prompt for example), and then write the arguments after it.
So my question is
How do i open my program using the Command-Line, and how do i enter the arguments after the program name?
Some ways how arguments can be passed to a program:
Open your command prompt (like
cmd.exe
or PowerShell on Windows), then type:your_program.exe arg1 arg2 arg3
.You can do the same thing in a shortcut or a script (like a batch or sh script).
Edit the run configuration in your IDE.
For instance, Eclipse alllows you to set command-line arguments separately for each run configuration. This is helpful during development and debugging.
On Windows, drag and drop a file onto the executable. The dragged file's filename will be passed as a command-line argument.
On Windows, associate a filename extension with a filetype (
assoc
command) and associate that filetype with a command that runs your program (ftype
command). Now when such a file is opened, either in the command interpreter or by e.g. double clicking, what happens behind the scenes is that your program is run with the path to that file as argument.Run your executable programatically from another program and pass arguments as variables.
For instance in Python:
subprocess.call(['my_program.exe','arg1','arg2'])
You can do this by either opening a command prompt and cd to the path and enter the exe name followed by your params:
where your exe is bob and the two params are bob and dylan...
...or you can make a shortcut and right click, choose properties, shortcut and add the params to the end of the target field.
There may be an option in your IDE depending on what that is.
You can write when launching from command prompt, you can make shortcut and add arguments after name, you can add arguments in some IDE when debugging or you can cal your program with other program using some arguments.
Here's a simple example I use in linux
and u can parse it like this
I'm going to assume you're using an IDE, and I'll take a wild guess that it's Visual Studio. If I'm right, there are two approaches - one, open up the folder containing the executable that's been built - it'll be in {Solution Directory}/{Project Directory}/bin/{Build Configuration} by default. Run the command line there. The other option is to open the project properties, and under the "Debug" tab (in VS 2010 - it varies by version) put your command line flags in the box labeled "Command line arguments".