带boost的大整数:太大,无法用任何整数类型表示

big ints with boost : too large to be represented in any integer type

本文关键字:整数 任何 表示 类型 太大 boost      更新时间:2024-09-22

我想我没有得到什么。

boost::multiprecision中的类cpp_int是否应该包含所需大小的整数?假设我想存储下面这个大得离谱的整数。我该怎么做?

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
cpp_int n = 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;

以下代码返回

error: integer literal is too large to be represented in any integer type

如文档中所述,您需要使用字符串进行构造:

cpp_int n{"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"};

请参阅https://www.boost.org/doc/libs/1_74_0/libs/multiprecision/doc/html/boost_multiprecision/tut/conversions.html

相关文章: