I usually
int main()
We share a room
If you're working on C++ IDE,
Make the main function int main(int argc, char *argv[])
automatically.
The factor is when you call a function, but the main function is executed automatically Isn't it that I can't pass the factor to the main function? Why do you use that?
c++ ide parameter command-line-argument
The C/C program writes a command line argument.
argc
indicates the number of strings pointed to by argv
.
It is customary to write argc(argument count)
and argv(argument vector)
(intnum_args, char**arg_string)
It is okay to use another identifier
.
For example,
#include <iostream>
int main(int argc, char** argv) {
std::cout << "Have " << argc << " arguments:" << std::endl;
For (inti = 0; i < argc; ++i) { // number of factors (argc) output
std::cout << argv[i] << std::endl;
}
}
If you run the code together with ./testa1 b2 c3
Have 4 arguments:
./test
a1
b2
c3
will be printed.
© 2024 OneMinuteCode. All rights reserved.