std::stol():此函数将在函数调用中作为参数提供的字符串转换为long int。它解析str并将其内容解释为指定基数的整数,并将其作为long int类型的值返回。
用法:
long int stol (const string& str, size_t* idx = 0, int base = 10)
参数:该函数接受三个参数,如下所述:
str:它指定一个以整数表示的字符串对象。
idx:它指定一个指向size_t类型的对象的指针,该指针的值由函数设置为数值后str中下一个字符的位置。该参数也可以是空指针,在这种情况下不使用它。
base:它指定数字基来确定解释字符的数字系统。如果基数为0,则要使用的基数由序列中的格式确定。预设值为10。
返回值:该函数将转换后的整数返回为long int类型的值。
// CPP code for illustration
// of stol() function.
#include
using namespace std;
int main()
{
// converting decimal number.
string dec_num = "9876543210";
cout << "dec_num = " <<
stol(dec_num, nullptr, 10) << "\n";
// converting hexadecimal number.
string hex_num = "FFFFFF
如果觉得《stol函数在linux下使用 C++ std::stol() std::stoll()用法及代码示例》对你有帮助,请点赞、收藏,并留下你的观点哦!