std::stoi, std::stol, std::stoll
cppreference.com
<tbody>
</tbody>
int stoi( const std::string& str, size_t *pos = 0, int base = 10 ); |
(1) | ( C++11) |
long stol( const std::string& str, size_t *pos = 0, int base = 10 ); |
(2) | ( C++11) |
long long stoll( const std::string& str, size_t *pos = 0, int base = 10 ); |
(3) | ( C++11) |
str.
( std::isspace) , , -n ( n=base) . :
- ()
- () (
0), (,80) - () (
0x0X), (,160) - .
{0,2,3,...,36}. 2 {0,1}, 3 {0,1,2}, . , 10, , Aa 11, Zz 36. .
base 0, : 0, , 0x 0X, , .
pos. pos NULL, .
| str | ||
| pos | ||
| base |
, .
#include <iostream>
#include <string>
int main()
{
std::string test = "45";
int myint = stoi(test);
std::cout << myint << '\n';
}
:
45
.
(C++11) |
() |
(C++11)(C++11) |
() |
(C++11)(C++11)(C++11) |
() |
(C++11) |
string () |