如何使用BigInteger Microsoft库在C++中将字符串转换为BigInteger类型



不幸的是,我在BigInteger库中的BigInteger.Parse(String, NumberStyles)方法有问题。我试着在C++程序中使用它,但它不起作用。我不确定,但也许是因为微软不再提供使用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()不接受std::string作为输入。它需要一个System::String。请参阅MSDN文档中的"如何:将标准字符串转换为系统::字符串"。

例如:

String^ str2 = gcnew String(str.c_str());
result = BigInteger::Parse(str2, NumberStyles::AllowHexSpecifier);

最新更新