c++ long long int 还不够吗?错误
我正在使用 c++ 工作。我有一个包含以下数字的字符串
std::string s= "8133522648";
,我想转换该数字
long long int nr;
:nr=atoll(s.c_str())。
结果是:-456410944
。如何解决这个错误?谢谢
编辑:
事实上我有:
const char* str="8133523648";
I have to convert it into long long int nr=8133523648
感谢您的帮助!欣赏!
I am working in c++. I have a string that contains the following number
std::string s= "8133522648";
I want to convert this number in
long long int nr;
I did: nr=atoll(s.c_str()).
The result is: -456410944
. How to solve this error? Thanks
Edit:
In fact I have:
const char* str="8133523648";
I have to convert it into long long int nr=8133523648
Thanks for help! Appreciate!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 int64_t 而不是 long long。这是在 stdint.h 中定义的
如果你依赖 boost 你可以使用
use int64_t instead of long long. which is defined in stdint.h
If you rely on boost you can use
可以通过以下更好的方式完成:
不要使用
atoll()
,因为它不是由 C++ 标准定义的。有些编译器可能会实现它,而其他编译器则不会。另外,并不意味着
这可能就是您想要的。
It can be done in better way as follows:
Don't use
atoll()
as it is not defined by C++ standard. Some compiler may implement it while others don't. Also,doesn't mean
which was probably what you wanted.
下面的代码工作正常:
Below code is working fine: