在c ++中将字符串转换为unsigned long long

时间:2014-01-29 05:21:07

标签: c++ casting type-conversion

将字符串转换为无符号长整数。

string str = "0x1232"

如何转换为无符号长整数。

这就是我尝试过的。

unsigned long long ull;
ull = stoull(str, NULL, 0);

错误:

 error: identifier "stoull" is undefined
                        ull = stoull(str, NULL, 0);

你能给我一些指示吗?

1 个答案:

答案 0 :(得分:5)

首先是strtoull(注意r)。其次,它是一个旧的C风格函数,无法直接处理std::string。您必须通过str.c_str()或使用新的std::stoull

相关问题