title: How to print a stack using arrays in c++
body: <p>I have added all the required functions - e.g. push, pop and print - in my program, but am unable to print stack output on the console screen. I created three separate files containing classes, functions and the main file. I want to know that the elements I am inserting in the stack are successfully inserted therefore I need to print the updated stack.</p>
  
  <p>stack.h</p>
  
  <pre><code>#ifndef Stack_H
  #define Stack_H
  
  using namespace std;
  
  class Stack{
  private: 
  //int const capacity=50;
  int stack[50];
  
  int count;
  int top;
  int maxitem;
  
   public:  //this is where the functions go
   Stack();//constructor
   void Push(int data);
   void Pop(int delData);
   void PrintStack();
   };
  
  
  #endif 
  </code></pre>
  
  <hr>
  
  <p>stack.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include "Stack.h"
  
  using namespace std;
  
  Stack::Stack()
  {
      top=-1;
  };
  
  void Stack::Push(int data){
      top++;
      cin&gt;&gt;data;
      stack[top]=data;
      count++;
      cout&lt;&lt;"inserted succefully :"&lt;&lt;data&lt;&lt;endl;
  }
  
  void Stack::Pop(int item)
  {
   if(top&lt;0){
   cout&lt;&lt;"stack is empty";
              }
   else{
       item=stack[top];
       top--;
  
      cout&lt;&lt;"The deleted elememt is: "&lt;&lt;item&lt;&lt;endl;
       }
  }
  
  
  void Stack::PrintStack()
  {
      if (top&lt;0)
      {
          cout&lt;&lt;"Stack is empty ";
      }
      for(int i =top; i&lt;0; i--)
      {
          cout&lt;&lt;"STACK IS "&lt;&lt;stack[i]&lt;&lt;"  "&lt;&lt;endl;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;stack&gt;
  #include "Stack.h"
  
  using namespace std;
  
  
  int main()
  {
      Stack R;
      int ele;
      int data;
      cout&lt;&lt;"enter the maximum elements in stack "&lt;&lt;endl;
       cin&gt;&gt;ele;
      cout&lt;&lt;endl&lt;&lt;"now enter the elements in stack "&lt;&lt;endl;
  
  
      for(int data=0; data&lt;ele; data++){
      R.Push(data);
  
      R.PrintStack();
      }
  
  
      R.Pop(item);
      R.PrintStack();//stack after deletion of element
  
  
      system("pause");
  }
  </code></pre>