可以使用 cstring頭文件中的stoi函數實現:字符串轉數字,數字進行進制轉換
#include <bits/stdc++.h>
using namespace std;
int main() {
int a=stoi("12",0,16);
//字符串 12 從第0位開始 轉換成16進制
cout <<"十進制:12 轉換成 十六進制:" <<a<<endl;
a=stoi("12",0,8);
//字符串 12 從第0位開始 轉換成8進制
cout <<"十進制:12 轉換成 八進制:" <<a<<endl;
return 0;
}