如何使用 BigInteger Microsoft 库在 C++ 中将字符串转换为 BigInteger 类型
How to convert a string to the BigInteger type in C ++ using the BigInteger Microsoft library
不幸的是,我对 BigInteger 库中的 BigInteger.Parse(String, NumberStyles)
方法有疑问。我尝试在 C++ 程序中使用它,但它不起作用。我不确定,但也许是因为 Microsoft 不再提供使用 Parse()
方法的机会?
如何在 C++ 中将 string
转换为 BigInteger
?
using namespace System::Numerics;
...
static unsigned char hexArr[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
ostringstream oss;
for (size_t i = 0; i <1024; i++)
oss << hexArr[rand() % 16];
string str(oss.str());
// Another way to get str, but it doesn't solve the problem
//str += hexTable[rand() % 16];
result = BigInteger::Parse(str, NumberStyles::AllowHexSpecifier); // My problem here
BigInteger::Parse()
doesn't take a std::string
as input. It takes a System::String
instead. See How to: Convert Standard String to System::String 在 MSDN 的文档中。
例如:
String^ str2 = gcnew String(str.c_str());
result = BigInteger::Parse(str2, NumberStyles::AllowHexSpecifier);
不幸的是,我对 BigInteger 库中的 BigInteger.Parse(String, NumberStyles)
方法有疑问。我尝试在 C++ 程序中使用它,但它不起作用。我不确定,但也许是因为 Microsoft 不再提供使用 Parse()
方法的机会?
如何在 C++ 中将 string
转换为 BigInteger
?
using namespace System::Numerics;
...
static unsigned char hexArr[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
ostringstream oss;
for (size_t i = 0; i <1024; i++)
oss << hexArr[rand() % 16];
string str(oss.str());
// Another way to get str, but it doesn't solve the problem
//str += hexTable[rand() % 16];
result = BigInteger::Parse(str, NumberStyles::AllowHexSpecifier); // My problem here
BigInteger::Parse()
doesn't take a std::string
as input. It takes a System::String
instead. See How to: Convert Standard String to System::String 在 MSDN 的文档中。
例如:
String^ str2 = gcnew String(str.c_str());
result = BigInteger::Parse(str2, NumberStyles::AllowHexSpecifier);