简体   繁体   中英

C++ no match for 'operator=' (postfix to infix)

I am writing this program that converts postfix to infix. I manage to code a program that does the opposite but when I try to create this particular program I have encountered many issues that I can't really understand what I am doing wrong.

The following is my program: I can't get it to compile. in my mind, it is a simple problem but I just can't figure out the issue.

/*
 * crate function toInfix
 * create empty stack
 * initialize output, and operand1 and operand2 variables strings
 * for loop entired input
 * if input is operator
 * pop thwo operands from the stack
 * combine the two operands with the operator in between
 * push the new expression on the stack
 * if input is operand then push in the stack
 */

string toInfix(string input)
{
    stack <char> stk;
    string output, oprnd1, oprnd2;
    for(auto& in : input)
    {
        if(isSymbol(in))
        {
            oprnd1 = stk.pop();
            oprnd2 = stk.pop();
            output = oprnd1 + in + oprnd2;
            stk.push(output);
        }
        stk.push(in);
    }
    while(!stk.empty())
    {
        output = stk.pop();
    }
    return output;
}

Like Benjamin said, pop returns void. Therefore, setting a string to void is not possible. To fix this, set it equal to the top element, and then pop it.

output += stk.top();
stk.pop();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM