温馨提示×

C++ stoll如何转换大数字符串

c++
小樊
87
2024-07-08 17:18:14
栏目: 编程语言
C++开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在C++中,可以使用std::stoll函数将大数字符串转换为长长整型(long long int)。示例如下:

#include <iostream>
#include <string>

int main() {
    std::string bigNumStr = "12345678901234567890";
    long long int bigNum = std::stoll(bigNumStr);
    
    std::cout << "The converted big number is: " << bigNum << std::endl;
    
    return 0;
}

在上面的示例中,首先将大数字符串"12345678901234567890"赋值给bigNumStr变量,然后使用std::stoll函数将该字符串转换为长长整型,最后输出转换后的大数。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:C++ stoll性能表现怎样

0