#include <iostream>
using std::cout;
bool help = 0;
bool expl = 0;
int main(int argc, char *argv[])
{
for(int i=1; i + 1 <= argc; i++)
{
if((argv[i] == "-h" | argv[i] == "--help" ) && help != 1)
{
cout << "This is an experiment for parsing arguments.\n"
<< "Possible arguments are:\n"
<< "-h : Show this help.\n"
<< "-e : a short explanation.\n";
help = 1;
}
else if((argv[i] == "e" | argv[i] == "--expl" ) && expl != 1)
{
cout << "This program uses a for loop to get i variable value.\n"
<< "The i variable is used with an if loop to check for arguments.\n";
expl = 1;
}
else
{
cout << "Invalid argument: " << argv[i] << "\n";
}
}
return 0;
}
My problem is that I always get the "Invalid argument" message. Any hints?