std::stoul
Defined in header <string> | | |
|---|---|---|
unsigned long stoul( const std::string& str, std::size_t* pos = 0, int base = 10 ); unsigned long stoul( const std::wstring& str, std::size_t* pos = 0, int base = 10 ); | (1) | (since C++11) |
unsigned long long stoull( const std::string& str, std::size_t* pos = 0, int base = 10 ); unsigned long long stoull( const std::wstring& str, std::size_t* pos = 0, int base = 10 ); | (2) | (since C++11) |
解释字符串中的无符号整数值。str...
1%29次电话std::strtoul(str.c_str(), &ptr, base)或std::wcstoul(str.c_str(), &ptr, base)
2%29次电话std::strtoull(str.c_str(), &ptr, base)或std::wcstoull(str.c_str(), &ptr, base)
丢弃通过调用所标识的任何空白字符%28isspace()%29直到找到第一个非空白字符,然后尽可能多地接受字符以形成有效的字符。基-n%28其中n=基%29无符号整数表示并将它们转换为整数值。有效的无符号整数值由以下部分组成:
- %28可选%29加或减符号
- %28可选%29前缀%28
0%29表示八进制基%28仅在基为8或0%29
- %28可选%29前缀%28
0x或0X%29表示十六进制基%28仅在基为16或0%29
- 数字序列
基的有效值集为{0,2,3,…,36}。基-2整数的有效数字集是{0,1},对于基-3整数是{0,1,2}等等。对于大于10,有效数字包括字母字符,从Aa对于基数-11整数,到Zz基-36整数。字符的情况被忽略。
当前安装的C可以接受其他数字格式locale...
如果基值为0,则自动检测数字基:如果前缀为0,则基为八进制,如果前缀为0x或0X,则基为十六进制,否则基为十进制。
如果减号是输入序列的一部分,则从数字序列中计算的数值将被否定,就像一元减去在结果类型中,该类型应用无符号整数环绕规则。
如果pos不是空指针,则是指针。ptr中的第一个未转换字符的地址。str.c_str(),则该字符的索引将被计算并存储在*pos,给出通过转换处理的字符数。
参数
str | - | the string to convert |
|---|---|---|
pos | - | address of an integer to store the number of characters processed |
base | - | the number base |
返回值
转换为指定的无符号整数类型的字符串。
例外
std::invalid_argument如果不能执行转换
std::out_of_range如果转换后的值超出结果类型的范围,或者如果基础函数%28 std::strtoul或std::strtoull%29集errno到ERANGE...
另见
stoistolstoll (C++11)(C++11)(C++11) | converts a string to a signed integer (function) |
|---|---|
stofstodstold (C++11)(C++11)(C++11) | converts a string to a floating point value (function) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

