If you know VB, you know that you receive command-line arguments in Command$. How do you get the arguments through C++? Its just a DOS console app, if that makes any difference :rolleyes:
Printable View
If you know VB, you know that you receive command-line arguments in Command$. How do you get the arguments through C++? Its just a DOS console app, if that makes any difference :rolleyes:
All console apps begin with the function main that looks like this:
argc - Number of elements in the arg array.Code:int main(int argc, char* argv[])
{
return 0;
}
argv - Array of command-line arguments.
Rippin
I forgot to mention,
your version of main does not have to have the same signature as the one I wrote in my last post. Alot of times you see main defined like this:
All you have to do is change your main function to take the parameters listed in my last post.Code:int main(void)
{
return 0;
}
cool, thanks. :D I'll work with it
I think the first argument passed in is always the path to the file being executed. I'm not exactly sure, but I think I read that.
Code:argc
An integer specifying how many arguments are passed to the program from the command line. Because the program name is considered an argument, argc is at least 1.
argv
An array of null-terminated strings. It can be declared as an array of pointers to char (char *argv[ ] or wchar_t *argv[ ] for wmain) or as a pointer to pointers to char (char **argv or wchar_t **argv for wmain). The first string (argv[0]) is the program name, and each following string is an argument passed to the program from the command line. The last pointer (argv[argc]) is NULL.