|
-
May 22nd, 2001, 08:30 PM
#1
command-line extras...
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
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 22nd, 2001, 09:51 PM
#2
Member
All console apps begin with the function main that looks like this:
Code:
int main(int argc, char* argv[])
{
return 0;
}
argc - Number of elements in the arg array.
argv - Array of command-line arguments.
Rippin
-
May 22nd, 2001, 09:53 PM
#3
Member
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:
Code:
int main(void)
{
return 0;
}
All you have to do is change your main function to take the parameters listed in my last post.
-
May 22nd, 2001, 09:54 PM
#4
cool, thanks. I'll work with it
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 23rd, 2001, 05:30 AM
#5
Frenzied Member
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.
Harry.
"From one thing, know ten thousand things."
-
May 23rd, 2001, 07:22 AM
#6
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|