command line arguments

Started by
2 comments, last by Sand_Hawk 21 years, 6 months ago
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
----------------(Inspired by Pouya)
Advertisement
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

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];...} 
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];...} 
Working on: DoP

This topic is closed to new replies.

Advertisement