Running on Widows 7 with MSVS 2010
使用MSVS 2010的寡妇7
I am following this tutorial to understand how to use MPIR library for adding two big integers
我将通过本教程了解如何使用MPIR库来添加两个大整数
I understand this library should help me in adding very big numbers as shown in the program below:
我明白这个图书馆应该帮助我增加非常大的数字,如下图所示:
#include < stdio.h>
#include < stdlib.h>
#include < gmpxx.h>
#include < iostream>
using namespace std;
void main(int argc, char *argv[])
{
mpz_class answer_a = 111111111111111111111111111111111111111111111111;
mpz_class answer_b = 111111111111111111111111111111111111111111111111;
mpz_class answer_c;
answer_c= answer_b + answer_a ;
cout << answer_c<<"\n";
}
But still I get error C2177: constant too big
. Did I misunderstand MPIR ?
但我还是会得到错误C2177:常数太大。我是否误解了MPIR ?
1 个解决方案
#1
4
Such constant is (very likely) too big for standard integer types. You should use char *
constructor instead:
对于标准整数类型来说,这样的常量(很可能)太大了。你应该使用char *构造函数代替:
void mpz_class::mpz_class (const char *s)
For example:
例如:
mpz_class answer_a("111111111111111111111111111111111111111111111111");
to make this work you need to include suitable MPIR C++ interface header (notice that <gmpxx.h>
is from C++ interface of GNU MP library):
要完成这项工作,您需要包含合适的MPIR c++接口头(请注意
#include <mpirxx.h>
# include < mpirxx.h >
See 12.2 C++ Interface Integers chapter in MPIR documentation for more details.
有关更多细节,请参阅MPIR文档中的12.2 c++接口整数章节。
#1
4
Such constant is (very likely) too big for standard integer types. You should use char *
constructor instead:
对于标准整数类型来说,这样的常量(很可能)太大了。你应该使用char *构造函数代替:
void mpz_class::mpz_class (const char *s)
For example:
例如:
mpz_class answer_a("111111111111111111111111111111111111111111111111");
to make this work you need to include suitable MPIR C++ interface header (notice that <gmpxx.h>
is from C++ interface of GNU MP library):
要完成这项工作,您需要包含合适的MPIR c++接口头(请注意
#include <mpirxx.h>
# include < mpirxx.h >
See 12.2 C++ Interface Integers chapter in MPIR documentation for more details.
有关更多细节,请参阅MPIR文档中的12.2 c++接口整数章节。