gpt4 book ai didi

c++ - 将 CryptoPP::Integer 类型转换为 int

转载 作者:太空宇宙 更新时间:2023-11-04 13:06:17 24 4
gpt4 key购买 nike

我对 Crypto++ 库没有任何经验。在我的项目中,我需要将 Integer 类型转换为 int。这就是我正在尝试的:

int low_bound1=8;
int low_bound2=9;
Integer x=1,y=2;
low_bound1=(int)x;
low_bound1=(int)y;

这是我遇到的错误:

error: invalid cast from type 'CryptoPP::Integer' to type 'int'

可以吗?如果是那么怎么办?

最佳答案

Is it possible to do? If yes then how?

是的,它可能可以做到,但不是简单的 C 风格转换。

这是手册中关于 Integer 类的文档:Integer Class Reference .在ACCESSORS 标题下,有两种方法:

bool IsConvertableToLong () const
Determines if the Integer is convertable to Long. More...

signed long ConvertToLong () const
Convert the Integer to Long. More...

所以你需要做类似的事情:

int low_bound1, low_bound2;
Integer x=1,y=2;

if (x > std::numeric_limits<int>::max() || x < std::numeric_limits<int>::min())
throw std::out_of_range("Integer x does not fit int data type");

if (y > std::numeric_limits<int>::max() || y < std::numeric_limits<int>::min())
throw std::out_of_range("Integer y does not fit int data type");

low_bound1 = static_cast<int>(x.ConvertToLong());
low_bound2 = static_cast<int>(y.ConvertToLong());

关于c++ - 将 CryptoPP::Integer 类型转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42176218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com