Archived

This topic is now archived and is closed to further replies.

Sand_Hawk

command line arguments

Recommended Posts

I''m writing an app that is going to be command line. I am using Win32 console, how do I make it accept command line arguments? Sand Hawk ---------------- -Earth is 98% full. Please delete anybody you can.
My Site

Share this post


Link to post
Share on other sites
If you are writing a console app you will recognise..

int main(int argc,char *argv[])

argc is the counter of arguements you have sent, and argv is the array that contains them..

I think that the first

argv[0] = the full filepath of application
argv[1]... etc = arguements seperated by spaces

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can accept command line arguments using argc and argv.

i.e.

int main(int argc, char* argv[])
{
//use argc to see how many arguments were passed
if(argc < 2)
std::cerr<<"Not enough arguments\n";

//now use the first argument, argv[0] is the app.exe
std::string str = argv[1];
...
}

Share this post


Link to post
Share on other sites
You can accept command line arguments using argc and argv.

i.e.

int main(int argc, char* argv[])
{
//use argc to see how many arguments were passed
if(argc < 2)
std::cerr<<"Not enough arguments\n";

//now use the first argument, argv[0] is the app.exe
std::string str = argv[1];
...
}

Share this post


Link to post
Share on other sites