Just add (int argc, char *argv[])to your main function. argc contains the number of arguments and argv the arguments themselves.
int main(int argc, char *argv[])
{
std::string str = "default";
if (argc > 1) { str = argv[1]; }
}
Note that the command is also included as an argument (for example, an executable file). Therefore, the first argument is actually argv [1].
source
share