it gives me that there's an error in declaring st in the print_reverse function cout<<st<<endl;
i've declared the st in the private..
#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_ITEMS=10;
int st[MAX_ITEMS];
int top;
public:
stack();
void push(int);
int pop();
bool isempty();
bool isfull();
void print();
void print_reverse(int);
};
stack::stack(){top=-1;}
void stack::push(int v){st[++top]=v;}
int stack::pop(){return st[top--];}
bool stack::isempty(){return (top==-1);}
bool stack::isfull(){return top==MAX_ITEMS-1;}
void stack::print()
{
while(!isempty())
cout<<pop()<<endl;
}
void print_reverse(int i)
{
if(i<MAX_ITEMS && i >= 0)
{
cout<<st[i]<<endl;
print_reverse(--i);
}
}
int main()
{
stack x;
int data;
ItemType item;
ifstream instream;
ofstream outstream;
instream.open("input.txt");
outstream.open("output.txt");
if(instream.fail()){
cout<<"Error opening file\n";
exit(1);
}
while ( !instream.eof() )
{
if (x.isfull())
break;
instream>> data;
item.Initialize(data);
int temp = item.getvalue();
x.push(temp);
x.print();
}
instream.close();
cout<<"--------\n";
x.print_reverse(MAX_ITEMS-1);
cin.get();
outstream.close();
return 0;
}