Hi I am relatively new to programing.
I want to create a C++ program that when you call it in CMD you can pass it variables.
For example in cmd
Myprograme.exe 11 32 232
So that it uses these values in the calculation.
C++
int main(float A, float B, float C){
float sum= A+B+C;
cout << sum;
return 0;
}
The standard signature of main
is as follows:
int main(int argc, const char **argv)
argc
is the number of comman-line arguments that were given to the program (including argument number 0 which is the program's name).
argv
is an array of nul-terminated character strings, each of which contains the appropriate command-line argument. argv[argc]
is a null pointer.
You can use these to parse the command-line arguments an pass them on to your computation.
For example, if you issue the following on the command line:
myprog.exe a bb c
argc
will be 4argv[0]
will be "myprog.exe"
argv[1]
will be "a"
argv[2]
will be "bb"
argv[3]
will be "c"
argv[4]
will be the null pointer