Verifying command line parameters on C++ main method
1 min read
1 min read
int main(int argc, char **argv) {The checking of the correct number of parameters is done with the "argc" parameter of the main method, while the actual reading is done by using the argv parameter, i.e. argv[1] for the 1st parameter.
if(argc < 3){
...
//give some useful information to the user, i.e. the number
//of required parameters and maybe also a short example
...
//stop the execution of the program
return EXIT_FAILURE;
}
}
string myString = argv[1]