将16进制字符串转化为10进制数输出

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
 string word;
 while (cin >> word)
 {
  int word_lenth = word.size();
  int temp=0;
  int n = 0;
  for (int i = 2; i < word_lenth; i++)
  {
   if ((word[i] >= 'A') && (word[i] <= 'F'))
   {
    n = word[i] - 'A' + 10;;
   }
   if ((word[i] >= '0') && (word[i] <= '9'))
   {
    n = word[i]-'0' ;
   }
   temp = temp * 16 + n;//最重要的一步
  }
  cout << temp << endl;

 }
 return 0;
}

原文地址:https://www.cnblogs.com/Rakint/p/9790569.html