1.顺序栈,比较有意思,顺序栈的代码网上到处都是,不放出来了,用法贴下
string s;
cin >> s;
//将16进制转换成10进制
int ten_value=HexToTen(s);
//cout << ten_value<<endl;
//将10进制转换成8进制=============顺序栈法
//先构造栈
SeqStack<int>stack;
//压入栈
while (ten_value)
{
stack.Push(ten_value % 8);
ten_value = ten_value / 8;
}
while (!stack.Empty())
{
int result_value = 0;
result_value=stack.Pop();
cout << result_value;
}
cout << endl;
system("pause");
return 0;
2.std的stringstream
string str;
getline(cin, str);
//十六进制转十进制
int value;
string hex_test = str;
stringstream ss1;
ss1.str(hex_test);
ss1 >> hex >> value;
//十进制转八进制
stringstream ss;
//十进制转八进制
ss << oct << value;
cout <<ss.str() << endl;