[英]How can I set value of a variable to an amount that is more than unsigned long long maximum value in C++?
我知道 C++ 中unsigned long long
类型的变量的最大值是:
18,446,744,073,709,551,615
但我不知道如何将变量的值设置为超过 18,446,744,073,709,551,615 的金额?
在 vanilla C++ 中,您不能,但是,您可以使用Boost 的多精度库。
也许你可以使用__int128
,唯一的问题是你不能使用cin
, cout
或printf
但你可以写一个 function 像这样:
//output
inline void write(__int128 x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
//input
inline __int128 read()
{
__int128 X=0,w=0; char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
return w?-X:X;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.