But if I do that, the write function runs even if I supply command line parameters. And if I simply remove the '-w' to leave a blank "", then it wont run at all.
default , in this example, is only being executed if one supplies improper command line switch, not by default (by simply running the program with no parameters), Which was my whole problem.
Thank you both for your feedback. I will work on it!
*edit* TheIdeasMan, it's still not working.
Since you both think switch would be better, I am certainly willing to rework my program, but I still have the problem of not being able to run the program without parameters.
My question is how do I run the write function by default with no command line parameters, but NOT run if I do supply parameters.
But I still have the problem of not being able to run the program without parameters.
You'll have to be more specific what you mean as these statements are ambiguous. If you mean you want to execute write in any case then you just need to put a call to that function in line 22 of last example.
Sorry ShiftLeft. I am a brand-newbie. I am taking a course in C++ and haven't even gotten to arrays yet!
I just wanted to venture off and learn some things for practicing reading from and writing to text files.
Anyways, just found a code snippet that works for what I wanted
if ( argc != 2 ) // argc should be 2 for correct execution
std::// We print argv[0] assuming it is the program name
cout<<"usage: "<< argv[0] <<" <filename>\n";
if (argc !=2){
std::cout << "Usage:" << '\n';
std::cout << "-w to write to file" << '\n';
std::cout << "-v to verify contents of file" << '\n';
std::cout << "-e to erase contents of file" << '\n';
}
This is what I was trying to do. I wanted to display usage if no command line arguments were used and didn't want it to display if command line arguments *were* used.