Why don't you just evaluate the postfix? You seem to ignore it once you've generated it. The whole point fo converting to postfix is because the evaluation is easy.
There was nothing wrong to the conversion to postfix, that bit was fine. It was the evaluation that was broken.
To evaluate, start with the postfix expression.
1 2 3 4 5 6 7 8 9
for each token:
if it's a number,
push it on the evaluation stack
else
pop two numbers off the evaluation stack
apply the operation
push the result
display the number on the top of the stack
So, lets take your example.
infix: 2*(2+2) = 2 * 4 = 8
postfix: 222+*
push 2
push 2
push 2
pop 2 and 2, add them and push the result, (push 4)
pop 4 and 2, multiply them, push the result, (push 8)
I don't understand why you're passing in a stack into the function. I've described an algorithm that starts with an postfix expression in a string, returns a single value and uses a stack within the process.
You've already done the hard part, the infix to postfix converter. Just take string output from that and pass it to the evaluator.
You write out the postfix expression, with .print, just make it write to a general stream instead of stdout.
For example:
1 2 3 4 5
void stack::print(std::ostream &os)
{
for (int i=0; i <= top; ++i)
os << data[i];
}
Then you can print to an in-memory stream and convert that to a string:
1 2 3 4 5 6
std::ostringstream os; // in-memory stream
post.print(os); // write the stack content to the stream
std::string postfix = os.str(); // save the stream into a string
int value = evaluate(postfix); // evaluate the postfix expression
std::cout << "postfix expression: " << postfix << std::endl;
std::cout << "value: " << value << std::endl;