//************************************** // Name: Scan command arguments v2.0 // Description:This is a small project to scan and process a command line with command flags set code is very simple and made for a beginner hope you find is helpfull. // By: Ben128 // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //************************************** // Scan and process command line arguments // By DreamVB #include <iostream> using namespace std; using std::cout; using std::endl; int main(int argc, char *argv[]){ //Sample commmand line //app.exe -a -b FileToProcess.txt //Exit if no arguments if(argc <=1){ return 0; } //Get part appname argv++; //Check if argc is > 1 and then scan for flag char - and process as required. while (argc > 1 && *(*argv)++== '-'){ if(argv){ //By here we can now do what ever with switchs found. switch(toupper(**argv)){ case 'A': cout << "A Flag was found, Put your code here" << endl; break; case 'B': //make a beep. cout << (char)7; break; case 'H': cout << "You can put your help message here." << endl; exit(1); default: cout << "Unknown input argument found." << endl; break; } } //Get next argc--; argv++; } //Move back one so we can get the filename at the end of the flags (*argv)--; //Print out file name cout << "Filename = " << argv[0] << endl; system("pause"); return 1; }