title: pushing values to stack class using linked list struct c++
body: <p>So I am implementing a stack class using linked lists and I need to push a string into the stack but the stack can only hold ints. I am trying to split the string into ints and push each one of them into the stack but no dice. </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  using namespace std;
  
  class Stack {
  public: 
      Stack() { 
          top = NULL;
          count = 0;
          size = 0;
      }
  
      void push(int numberToPush) {
          //create a new linkedlistnode assing its value to number to push
          //and add it to the underlying linkedlist structure
          LinkedListNode *n = new LinkedListNode;
          n -&gt; val = numberToPush;
          n -&gt; next = top;
          top = n;
          size++;
      }
  
      int pop() {
          //returns value of the node at the top of the stack and removes the node
          if(isEmpty()) {
              cout &lt;&lt; "stack is empty pop" &lt;&lt; endl; 
              return -1;
          }
  
          LinkedListNode *temp = top;
          top = temp -&gt; next;
          return temp -&gt; val;
      }
  
      int peek() {
          //returns the value of the node at the top of the stack, but does not remove the node
          if(isEmpty()) {
              cout &lt;&lt; "stack is empty" &lt;&lt; endl; 
              return -1;
          }
  
          return top -&gt; val;
      }
  
      void display() {
          LinkedListNode *n = top;
  
          for(int i = 0; i &lt; size; i++) {
              cout&lt;&lt; top-&gt;val &lt;&lt; ", ";
              top=top-&gt;next;  
          }
      }
      bool isEmpty() {
          return top == NULL;
      }
  
  private:
  struct LinkedListNode {
          int val;
          LinkedListNode *next;
  
  };
  
      LinkedListNode* top;
      int count; 
      int size;
  };
  
  int main() {
      string Input; 
  
      cout &lt;&lt; "enter a word or phrase: ";
      cin &gt;&gt; Input;
  
      Stack s;
  
      for(int i = 0; i &lt; Input.length(); i++)
          s.push(Input[i]);
  
      s.display();
  
      return 0; 
  }
  </code></pre>