With your example, you're just pushing the "+" sign on the stack, but you never pop it because after processing the symbol "8", you've left the for
loop. I think you need another while loop to empty your stack at the end.
for(int i=0;i<infix.length();i++){
if(isdigit(infix[i]) or isalpha(infix[i])){
postfix += infix[i];
}
else if(infix[i] == '+' or infix[i] == '-' or infix[i] == '*' or infix[i] == '/' or infix[i] == '^'){
while(isp(stack1.top()) >= icp(infix[i])){
postfix += stack1.pop();
}
if(isp(stack1.top()) < icp(infix[i])){
stack1.push(infix[i]);
}
}
}
// Fetch the remaining operators from the stack
while(!stack1.is_empty()){
postfix += stack1.pop();
}
cout << postfix;
Beware of bugs, as I couldn't test this code myself.