int main(int argc, char* argv[])
    std::cout << argc << std::endl;

The code above will print a number depending on the number of arguments added to it. However I am writing a game in c++/python and I need the program to accept a integer argument that will define the current level the player is on. May someone please show me how?

Use stringstreams for formating.Argc will always contain the number of arguments passed to the program at the command line so you can't use that directly.Argv is an array in which you can index an argument like this:


Use a stringstream for formatting the input instead

int value;
std::istringstream (argv[argc-1]) >> value; 
//returns the last argument in this case and converts it to an integral type

Or if stringstream is too advanced, atoi(argv[i]) will also suffice.
i will be an index into the argv array.

Thank you I will use the atoi method, although I will look into the concept of string streams.

This question has already been answered. Start a new discussion instead.