c++ Why can't I use static_cast to convert char* to int?
问题 number = static_cast<int>(argv[1]); Error: Using static_cast to convert from char* to int not allowed. I've tried finding out why on google and I just can't seem to find it. Also, I don't want to get the ascii value, because argv[1] is a number. e.g. ./prog 15 cout << number; //want it to print 15. 回答1: You just try to convert char* to int. You code should be: int number = atoi(argv[1]) 回答2: You can use this: std::stoi function. It's totally C++ , not like one borrowed from c libraries.. atoi