c ++为什么不能使用static_cast将char *转换为int? [英] c++ Why can't I use static_cast to convert char* to int?
本文介绍了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])
这篇关于c ++为什么不能使用static_cast将char *转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文