c ++为什么不能使用static_cast将char *转换为int?
问题描述:
number = static_cast<int>(argv[1]);
错误:使用static_cast从char *转换为int不允许。
Error: Using static_cast to convert from char* to int not allowed.
我试着找到为什么在谷歌和我只是似乎找不到它。
此外,我不想得到ascii值,因为argv [1]是一个数字。
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.
例如。 ./prog 15
e.g. ./prog 15
cout<数; //要它打印15。
cout << number; //want it to print 15.
答
你只是试图将char *转换为int。您的代码应为:
You just try to convert char* to int. You code should be:
int number = atoi(argv[1])