I intend to enter a number into the command line such as saying “./a.out 3” where 3 would be the number I’m trying to retrieve. I’m wondering why in my example, the two numbers I’m trying to output aren’t the same, and what is the most practical way of extracting info from the command line args? Thanks
int main(int argc, char* argv[]){
char* openSpace = argv[1];
int temp = *openSpace;
cout<<*openSpace<<" is the open spot!"<<endl;
cout<<temp<<" is the open spot!"<<endl;
return 0;
}
argv[1]is achar*and you want anint. Unfortunately, you cannot just change the type of the variable. Instead, you must convert thechar*to anint. Use theatoi()function for this.