function template
<string>
std::stoullunsigned long long stoull (const string& str, size_t* idx = 0, int base = 10);unsigned long long stoull (const wstring& str, size_t* idx = 0, int base = 10);
Convert string to unsigned long long
Parses str interpreting its content as an integral number of the specified base, which is returned as a value of type unsigned long long.If idx is not a null pointer, the function also sets the value of idx to the position of the first character in str after the number.
The function uses strtoull (or wcstoull) to perform the conversion (see strtol for more details on the process).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// stoull example
#include <iostream> // std::cout
#include <string> // std::string, std::stoull
int main ()
{
std::string str = "8246821 0xffff 020 -1";
std::string::size_type sz = 0; // alias of size_t
while (!str.empty()) {
unsigned long long ull = std::stoull (str,&sz,0);
std::cout << str.substr(0,sz) << " interpreted as " << ull << '\n';
str = str.substr(sz);
}
return 0;
}
8246821 interpreted as 8246821 0xffff interpreted as 65535 020 interpreted as 16 -1 interpreted as 18446744073709551615
If the value read is out of the range of representable values by a unsigned long long, an out_of_range exception is thrown.
An invalid idx causes undefined behavior.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4