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)?
|
1 answer
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
|
main
... - HarryPATH
? - HolyBlackCat