Hey all,
I have a small program that takes one of two argument switches and then runs. If no argument is given, it runs in interactive mode and asks you which option you would like.
My problem is that if I want to redirect the output to a txt file using >> the program reads it as an argument. How can I tell my code to allow redirect?
I have a small program that takes one of two argument switches and then runs. If no argument is given, it runs in interactive mode and asks you which option you would like.
My problem is that if I want to redirect the output to a txt file using >> the program reads it as an argument. How can I tell my code to allow redirect?
Code:
int main(int argc, char * argv[])
{
std::cout << std::string(50, '\n');
if (argc > 1)
{
if (std::string(argv[1]) == "-h")
{
function1();
}
else if (std::string(argv[1]) == "-s")
{
function2();
}
else
{
std::cout << " Please select a valid option." << std::endl;
std::cout << "-h for function1" << std::endl;
std::cout << "-s for function2" << std::endl;
std::cout << "blank for interactive mode" << std::endl;
}
}
else
{
interactiveMode();
}
}