首先把之前的MyStack改成int型:
#include <iostream> #include <stdlib.h> #include "MyStack.h" #include <algorithm> using namespace std; //用栈进行进制转换 #define BIN 2 #define OCT 8 #define HEX 16 int main(void) { MyStack *pStack = new MyStack(30); int N = 1348; while(N) { int tmp = N % OCT; pStack->push(tmp); N /= OCT; } pStack->stackTraverse(false); delete pStack; pStack = NULL; return 0; }