I am trying to make a CLI app in C++. This is my first time coding in C++.
I have this c++ code:
#include <iostream>
// using namespace std;
static void help(std::string argv)
{
std::cerr << "Usage:" << argv << " [options]\n"
<< "Options:\n"
<< "-h (--help): Displays this help message.\n"
<< "-o (--output=[output file]): Specifies the output file.\n"
<< "-p (--ports=[ports]) Sets the ports to scan.\n"
<< std::endl;
}
int main(int argc, char** argv)
{
if (argc > 1)
{
std::cout << argv[1] << "\n";
if (argv[1] == "-h" || argv[1] == "--help")
{
help(argv[0]);
return 0;
}
}
else
{
std::cout << "No arguments were given" << "\n";
};
};
// g++ -o cli main.cpp
It works! When I compile it, it successfully outputs No arguments were given
, but when I run cli -h
, I can see argv[1]
is -h, but nothing is outputted.
What did I do wrong?