0
我知道unsigned long
高達4294967295而已,所以這裏是我的問題,當用戶輸入多的數字(如結果是要超過上限值)轉換後的數字將是多麼4294967295。 例如:轉化基地11十進制
Base 11: 1928374192847
Decimal: 4294967295
的結果應該是5777758712535.如何解決這個限制? vb6.0需要給我們。 這裏是我的代碼:
cout << "\t\t CONVERSION\n";
cout << "\t Base 11 to Decimal\n";
cout << "\nBase 11: ";
cin >> str;
const auto x = str.find_first_not_of("aA");
if (x != string::npos)
{
std::cout << "Invalid Input\n\n";
goto a;
}
unsigned long x = strtoul(str.c_str(), NULL, 11);
cout << "Decimal: " << x << "\n\n";
程序應該說「超出範圍」如果結果將超過4294967295 對不起我只是個初學者。
[性病:: strtoul將(http://en.cppreference.com/w/cpp/string/byte/strtoul)將讓你知道,如果有一個誤差範圍。需要我們 – wally
*** *** VB6.0我想你指的Visual C++ 6.0。該代碼不是Visual Basic。 – drescherjm
@drescherjm幸運的代碼兼容。 –