argv
is of type char*[]
(array of char* pointers). You cannot directly compare string constants (type char*
), which you need to quote. Instead, I suggest you to convert it to a c++ string type:
#include <string>
void file(){
// ...
}
int main(int argc, char *argv[]) {
if(argc>=2)
{
if(std::string(argv[1]) == "open")
{
file();
}
}
else
{
// print usage
}
}