Hello all I am trying to read in expressions from a file and print them out in postfix. I can't seem to figure out how to make it read one line print out the expression in postfix and then read in the next line. For some reason it reads in all the data then prints out that in postfix.
Here is what is the the file:
2 + 3 * 5
2 + 3 * 5 ^ 6
Here is what it is printing:
2352*+356^*+
int priority(char a)
{
int temp;
if (a == '^')
temp = 3;
else if (a == '*' || a == '/')
temp = 2;
else if (a == '+' || a == '-')
temp = 1;
return temp;
}
int main()
{
string aline;
ifstream indata;
indata.open("infix.data");
so that they are inside the while-getline loop, just before the closing brace of that loop.
Also, you need to clear the contents of the stringstream so that it is empty at the start of each pass through the loop: output.str(""); // empty the stringstream
Also, please enclose your code in tags [code]your code here[/code]. The formatting button <> on the right hand side will add the tags for you.