#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?

On line 11 and 19 you cannot compare a char string using the == operator. Instead use strcmp http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html.

Line 11:

if((argv[i] == "-h" | argv[i] == "--help" ) && help != 1)

Should be:

if ((strcmp(argv[i], "-h") == 0) | (strcmp(argv[i], "--help") == 0)&&help != 1)

Do the same thing with line 19 and see if it works then.

You could also use std::string and then use the == operator to compare it with another string.

Comments
Helpful

Shouldnt You Be Using "||" For OR.

I mean

if((argv[i] == "-h" | argv[i] == "--help" ) && help != 1)

Should Be Actually

if((argv[i] == "-h" || argv[i] == "--help" ) && help != 1)

Right.

Good point!, he got me thicking strangely. But you cannot compare two arrays using the == operator.
So the correct way would be:

if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)&&help != 1)
This question has already been answered. Start a new discussion instead.