title: Stack Gotoxy Object Oriented
body: <p>i cant compile with gotoxy, its show me windows.h as an error, its an stack thats show, enter a number, delete top and shohw top, but gotoxy isnt work.</p>
  
  <p><strong>stack.h</strong></p>
  
  <pre><code>#ifndef STACK_H_INCLUDED
  #define STACK_H_INCLUDED
  
  #include &lt;exception&gt;
  #include&lt;string&gt;
  
  class StackException: public std::exception
  {
  private:
      std::string msg;
  public:
      explicit StackException(const char* message) :
              msg(message)
      {
      }
      explicit StackException(const std::string&amp; message) :
              msg(message)
      {
      }
      virtual ~StackException() throw ()
      {
      }
      virtual const char* what() const throw ()
      {
          return msg.c_str();
      }
  };
  
  ///DEFINITION
  template&lt;class T, int ARRAYSIZE = 1024&gt;
  class Stack
  {
  private:
      T data[ARRAYSIZE];
      int top;
  
      void copyAll(const Stack&lt;T, ARRAYSIZE&gt;&amp;);
  
  public:
      Stack(); ///constructor base
      Stack(const Stack&lt;T, ARRAYSIZE&gt;&amp;); ///constructor copy
      void initialize();
  
      bool isEmpty();
      bool isFull();
  
      void push(const T&amp;);
      void showStack();
  
      T pop();
  
      T getTop();
      void gotoxy(int, int);
  
      Stack&lt;T, ARRAYSIZE&gt;&amp; operator =(const Stack&lt;T, ARRAYSIZE&gt;&amp;); ///OPERATOR ASIGNED
  };
  
  ///IMPLEMENTATION
  using namespace std;
  
  template&lt;class T, int ARRAYSIZE&gt;
  Stack&lt;T, ARRAYSIZE&gt;::Stack() :
          top(-1)
  {
  }
  
  template&lt;class T, int ARRAYSIZE&gt;
  void Stack&lt;T, ARRAYSIZE&gt;::copyAll(const Stack&lt;T, ARRAYSIZE&gt;&amp; s)
  {
      int i(0);
      while (i &lt;= s.top)
      {
          this-&gt;data[i] = s.data[i];
          i++;
      }
      this-&gt;top = s.top;
  }
  template&lt;class T, int ARRAYSIZE&gt;
  Stack&lt;T, ARRAYSIZE&gt;::Stack(const Stack&lt;T, ARRAYSIZE&gt;&amp; s)
  {
      copyAll(s);
  }
  
  template&lt;class T, int ARRAYSIZE&gt;
  bool Stack&lt;T, ARRAYSIZE&gt;::isEmpty()
  {
      return top == -1;
  }
  
  template&lt;class T, int ARRAYSIZE&gt;
  bool Stack&lt;T, ARRAYSIZE&gt;::isFull()
  {
      return top == ARRAYSIZE - 1;
  }
  
  template&lt;class T, int ARRAYSIZE&gt;
  void Stack&lt;T, ARRAYSIZE&gt;::push(const T&amp; e)
  {
      if (isFull())
      {
          throw StackException("DATA OVERLOAD, PUSH");
      }
      data[++top] = e;
  }
  
  template&lt;class T, int ARRAYSIZE&gt;
  T Stack&lt;T, ARRAYSIZE&gt;::pop()
  {
      if (isEmpty())
      {
          throw StackException("DATA INSUFFICIENCY, POP");
      }
      return data[top--];
  }
  
  template&lt;class T, int ARRAYSIZE&gt;
  T Stack&lt;T, ARRAYSIZE&gt;::getTop()
  {
      if (isEmpty())
      {
          throw StackException("DATA INSUFFICIENCY, getTop");
      }
      return data[top];
  }
  
  template&lt;class T, int ARRAYSIZE&gt; ///&amp; reference
  Stack&lt;T, ARRAYSIZE&gt;&amp; Stack&lt;T, ARRAYSIZE&gt;::operator =(const Stack&lt;T, ARRAYSIZE&gt;&amp; s)
  {
      copyAll(s);
  
      return *this;
  }
  
  template&lt;class T, int ARRAYSIZE&gt;
  void Stack&lt;T, ARRAYSIZE&gt;::showStack()
  {
      int ayuda, i;
      if (!isEmpty())
      {
          system("cls");
          printf("\n\n\t\t%c%c%c%c%c  \n", 201, 205, 205, 205, 187);
          for (i = top; i &gt;= 0; i--)
          {
              printf("\t\t%c%c ", 186, 205);
              cout &lt;&lt; data[i];
              printf(" %c\n", 186);
              printf("\t\t%c%c%c%c%c\n", 204, 205, 205, 205, 185);
  
          }
          //system("pause");
      }
  }
  
  template&lt;class T, int ARRAYSIZE&gt;
  void Stack&lt;T, ARRAYSIZE&gt;::gotoxy(int x, int y)
  {
      HANDLE hcon;
      hcon = GetStdHandle(STD_OUTPUT_HANDLE);
      COORD dwPos;
      dwPos.X = x;
      dwPos.Y = y;
      SetConsoleCursorPosition(hcon, dwPos);
  }
  
  #endif // STACK_H_INCLUDED
  </code></pre>
  
  <p><em>The problem its with windows.h and gotoxy function</em></p>
  
  <p><strong>mainStack.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;cstdio&gt;
  #include &lt;string.h&gt;
  
  #include "stack.h"
  
  using namespace std;
  
  bool esNumeric(string);
  
  int main()
  {
      Stack&lt;string,10&gt; myStack;
      int opt,number;
      bool repeat = true;
      string line_;
  
          do{
              do{
                  system("cls");
                  myStack.showStack();
                  cout&lt;&lt;"\n\n---STACK---";
                  cout&lt;&lt;"\n 1) ENTER NUMBER\n 2) DELETE TOP\n 3) SHOW TOP \n 4) EXIT"&lt;&lt;endl;
                  cout&lt;&lt;"\tOPTION: ";
                  getline(cin,line_);
                  if (esNumeric(line_)) {
                      repeat = false;
                  }
              } while(repeat);
              opt = atoi(line_.c_str());
              switch(opt){
                  case 1:{
                          do {
                              system("cls");
                              cout&lt;&lt;"ENTER NUMBER: ";
                              getline(cin,line_);
                              if (esNumeric(line_)) {
                                      if(myStack.isFull()){
                                          cout&lt;&lt;"\nIT IS FULL"&lt;&lt;endl&lt;&lt;endl;
                                      }
                                      else{
                                           myStack.push(line_);
                                      }
                                  repeat = false;
                              }
                          } while (repeat);
                          system("pause");
                          system("cls");
                          break;
                  }
  
                  case 2:{
                          if(myStack.isEmpty()){
                              cout&lt;&lt;"\nEMPTY STACK"&lt;&lt;endl&lt;&lt;endl;
                          }
                          else{
                              myStack.pop();
                          }
                          system("pause");
                          system("cls");
                          break;
                  }
                  case 3:{
                          system("cls");
                          if(myStack.isEmpty()){
                              cout&lt;&lt;"EMPTY STACK";
                          }
                          else{
                          cout&lt;&lt;"\nTOP: "&lt;&lt; myStack.getTop()&lt;&lt;endl;
                          }
                          system("pause");
                          break;
                  }
                  case 4:{
                      cout&lt;&lt;" ";
                      break;
                  }
                  default:{
                      cout&lt;&lt;"\nOUT OF RANGE."&lt;&lt;endl;
                      system("pause");
                      system("cls");
                  }
              }
          }while(opt!=4);
          cout&lt;&lt;"\n\nEND OF THE PROGRAMF\n";
          system("pause");
          return EXIT_SUCCESS;
  }
  
  bool esNumeric(string line_)
  {
     bool b = true;
     int length = line_.size();
  
     if (length == 0) { // When user push ENTER
        b = false;
     } else if (length == 1 &amp;&amp; !isdigit(line_[0])) {
        b = false;
     } else {
        int i;
        if (line_[0] == '+' || line_[0] == '-')
           i = 1;
        else
           i = 0;
  
        while (i &lt; length) {
           if (!isdigit(line_[i])) {
              b = false;
              break;
           }
           i++;
        }
     }
  
     return b;
  }
  </code></pre>
  
  <p><strong>OUTPUT ERROR:</strong></p>
  
  <blockquote>
    <p>In file included from main.cpp:8: ./stack.h:132:7: error: unknown type
    name 'HANDLE' HANDLE hcon; ./stack.h:133:27: error: use of
          ^
    undeclared identifier 'STD_OUTPUT_HANDLE'hcon =
                                             ^
    GetStdHandle(STD_OUTPUT_HANDLE); ./stack.h:134:7: error: unknown
    type name 'COORD' COORD dwPos; 3 errors generated.
                      ^</p>
  </blockquote>
  
  <p><a href="https://repl.it/@ZayxHex/Stack-Validation-Gotoxy-Object-Oriented" rel="nofollow noreferrer">https://repl.it/@ZayxHex/Stack-Validation-Gotoxy-Object-Oriented</a></p>