c++ - 带 boost 的大整数:太大而无法以任何整数类型表示

标签 c++ boost c++17

我想我什么都没有。cpp_int中的boost::multiprecision类是否应该容纳想要的整数?
假设我要存储以下荒谬的大整数。我应该怎么做?

#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

关于c++ - 带 boost 的大整数:太大而无法以任何整数类型表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64793676/

相关文章:

c++ - GCC 7.3 是否省略了引用返回成员函数的 [[nodiscard]] 属性?

c++ - Win32下如何初始化Pango?

c++ - CLion C++ 无法读取/打开项目目录中的 .txt 文件

c++ - 打印出动态数组或矩阵的元素

c++ - Boost Asio 收到未知号码?

c++ - 在现代c++中,当 protected 资源需要通过getter作为shared_ptr返回时,如何设计单写和多读?

c++ - 将 argv 参数转换为 int

c++ - 链接失败,并带有对libboost_thread的 undefined reference

c++ - 使用boost库找到图形的最小切割

c++ - 结构化绑定(bind)在 C++17 中不起作用