--- In [email protected], andrew clarke <[EMAIL PROTECTED]> wrote:
>
> On Mon 2008-10-13 17:33:48 UTC-0000, fecress ([EMAIL PROTECTED]) wrote:
>
> > Please help me to write the code for a calculator that evaluates
> > postfix expressions using
> > stacks and reading input from a text file.
> > What template file do I need?
> > How can I read the postfix expression from file?
> > Please help!!!
>
> What have you done so far?
>
This is what I did so far,.....
Do I need a separate class, How many files do I need for this, or can I able to
put them all
in one file. This code below is not working?
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//Global Stuff
ifstream infile;
ofstream outfile;
int main(int argc, char *argv[])
{
Stack<string> ss;
char file[45];
string hold;
string operators;
string popme;
int numnum = 0;
int opnum = 0;
char ch;
ifstream File;
File.open("postfixtext.txt");
if (!File.is_open())
{
cout << "File not found!!!!";
exit(1);
}
else
{
cout << "Opening file.." << endl;
while(!file.eof())
{
ch = file.peek();
if (ch != ' ')
if ((ch >= '0') && (ch <= '9'))
{
file >> hold;
ss.push(hold);
numnum++;
}
if (ch == '+' || ch == '-' || ch == '*' || ch == '/')
{
file >> operators;
ss.push(operators);
opnum++;
}
else
file.ignore(1);
}
system("pause");
return 0;
}
I don't know what to do from here, Please help me!!!