argv is an array of strings, and argc says how many strings there are.
e.g. your program is at c:\test\program.exe. In a console you type:
>program.exe one two -g
if you debug, you will see in int main(int argc, char**argv)
argc = 4
argv[0] = "c:\test\program.exe"
argv[1] = "one"
argv[2] = "two"
argv[3] = "-g"
argv[0] is always the full path to the program.
I think if you program is used to open another type of file, e.g. .txt file, then this will happen:
argc = 2
argv[0] = "c:\test\program.exe"
argv[1] = "c:\the_file_that_you_chose.txt"
you can test what arguments you get with a loop:
|
Source code
|
1
2
3
4
5
6
|
#include <iostream>
int main(int argc, char*[] argv)
{
for (int i = 0; i < argc; ++i)
std::cout << argv[i] << " ";
}
|