What does int argc, char *argv[] mean?

前端 未结 8 2165
萌比男神i
萌比男神i 2020-11-21 05:18

In many C++ IDE\'s and compilers, when it generates the main function for you, it looks like this:

int main(int argc, char *argv[])

When I

8条回答
  •  無奈伤痛
    2020-11-21 05:51

    argc is the number of arguments being passed into your program from the command line and argv is the array of arguments.

    You can loop through the arguments knowing the number of them like:

    for(int i = 0; i < argc; i++)
    {
        // argv[i] is the argument at index i
    }
    

提交回复
热议问题