描述:
字符串转为有符号整数。
定义:
int atoi( const char *str );
long atol( const char *str );
long long atoll( const char *str );
int stoi( const std::string& str, std::size_t* pos = 0, int base = 10 );
int stoi( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
long stol( const std::string& str, std::size_t* pos = 0, int base = 10 );
long stol( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
long long stoll( const std::string& str, std::size_t* pos = 0, int base = 10 );
long long stoll( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
参数:
str - 要转换的字符串
pos - 存储已处理字符数的整数的地址
base - 数的底
返回值:
对应 str 内容的整数值。
用法:
#include <string>
int main()
{
const char* pStr = "99";
std::cout << std::atoi(pStr) << std::endl;//99
std::string str("80");
std::cout << std::stoi(str) << std::endl;//80
}
版权声明:本文为phd17621680432原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。