GMP是否具有将std字符串转换为整数的功能?
函数mpz_init_set_str
初始化并将char *转换为int。我想知道有没有对std字符串的支持?
只需使用c_str()函数访问底层char数组:
std::string str;
mpz_t strg;
mpz_init_set_str(strg, str.c_str(), 10);
GMP具有C ++绑定,因此使用gmpxx并且它可以正常工作。简单的任务将完成工作(所以没有锅炉板代码)。
Even introduction展示了这样的例子:
int main (void) { mpz_class a, b, c; a = 1234; b = "-5678"; c = a+b; cout << "sum is " << c << "\n"; cout << "absolute value is " << abs(c) << "\n"; return 0; }