mmmm i solved this problem but the program now doesnt do what i want it to do..i just wanted to display the items in the input.txt and then reverse these items in the stack..can u help?
here is the new code:
Code:
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include<cstdlib>
#include <fstream>
using std::ifstream;
using std::ofstream;
#include"ItemType.h"
using namespace std;
class stack
{
private:
static const int MAX=10;
int st[MAX];
int top;
public:
stack():top(-1){}
void push(int v){st[++top]=v;}
int pop(){return st[top--];}
bool isempty(){return (top==-1);}
bool isfull(){return top==MAX-1;}
void print()
{
while(!isempty())
cout<<pop()<<endl;
}
void print_reverse(int i)
{
if(i<MAX)
{
for(int j=i;j>=0;j--)
cout<<st[j];
}
}
};
int main()
{
stack x;
int data;
ItemType item;
ifstream instream;
ofstream outstream;
instream.open("input.txt");
if(instream.fail()){
cout<<"Error opening file\n";
exit(1);
}
outstream.open("output.txt");
if (!outstream)
return 0;
while(!x.isfull())
{
while ( !instream.eof() )
{
instream>> data;
item.Initialize(data);
int temp = item.getvalue();
x.push(temp);
x.print();
}
cout<<"--------\n";
x.print_reverse(data);
instream.close();
cin.get();
}
outstream.close();
return 0;
}