嵌套函数?Java里面都不可以,你还把它放到C++里?
My life is brilliant
#include <iostream> #include <cstring> #include <cstdlib> using namespace std; int HexToDec(const char* hex) { int dec = 0, digit; for (int i = strlen(hex) - 1, j = 1; i > -1; --i, j *= 16) { if (hex[i] >= '0' && hex[i] <= '9') digit = hex[i] - '0'; else if (hex[i] >= 'a' && hex[i] <= 'f') digit = hex[i] - 'a' + 10; else digit = hex[i] - 'A' + 10; dec += digit * j; } return dec; } int main() { char hex[] = "7FFFFFFF"; cout << HexToDec(hex) << endl; system("pause"); }