c++ - My output keeps getting appended to the previous output -


i'm writing program convert infix postfix. read infix data text file convert it.

the problem when outputing results, takes previous 1 , adds next 1 until end. i've been trying fix can't figure out happening! can see problem?

input:

    4     5+7     7*5 

output:

    4     457+     457+75* 

then prints again this:

 4457+457+75* 

my code:

int main() {     stack<char> stack;     string postfix = "";     const int size = 100;     char input[size];      ifstream file("tests.txt");     file >> input;          {        // code          cout<<"postfix :  " << postfix <<"\n";          file >> input ;     } while( file && file.peek() != eof);      system("pause");     return 0; } 

uhm - postfix.clear() @ end of loop?

also, try converting loop this:

ifstream file("tests.txt"); while(file.good()) {     file >> input;     ...     cout << "postfix : " << postfix << endl;     postfix.clear(); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -