1. 程式人生 > >C++標準庫之棧(Stack)實現進位制轉換

C++標準庫之棧(Stack)實現進位制轉換

#include <iostream>
#include <stack>
using namespace std;
int main()
{
	int b,n,e;
	cout << "請輸入數制轉換的進位制及數值:"<<endl;
	cin >> b >> n;
	cout << "數值" << n << "的" << b << "進製為:" << endl;
	stack<int>stk;
	while (n)
	{
		stk.push(n%b);
		n /= b;
	}
	while (!stk.empty())
	{
		cout << stk.top();
		stk.pop();
	}
	return 0;
}