How to create an application (in c ++) that can be run from a regular console, passing some parameters based on which it will do something (How to implement access to the application itself, what needs to be done to be able to reach it by name, as for example nmp in node.js , and a command to force to do something)?

  • four
    Read about the arguments of the function main ... - Harry
  • @Harry, yes, I admit, I don’t understand these arguments (I’ll read it), but I meant a little bit different: how to address the program, how to do it, and how to link it from the inside (although this is what you suggested). - Evgeny Babiychuk
  • Do you know what PATH ? - HolyBlackCat

1 answer 1

Something like this under Windows in the studio environment:

 #include <iostream> using namespace std; int main(int argc, char* argv[]) { if (argc > 1) { for (int i = 0; i < argc; i++) { cout << argv[i] << endl; if (strcmp(argv[i], "chto to delaet") == 0) { cout << "chto to vivodit" << endl; } else if (strcmp(argv[i], "1") == 0) { cout << "11111111111111111111" << endl; } } } else { cout << "Argymentov nety" << endl; } system("pause"); return 0; } 

In the console, write the program name and space separated arguments, for example:

 test.exe "chto to delaet" 1