I'm actually more comfortable in java, but I also want to learn C++ and so I started coding in it for past several days now, then I coded this stack's code which is giving me a hard time. It's giving a segmentation fault while trying to print the stack at last node.

Please guide me where I'm going wrong and anything wrong in this code that can be done in a better way.

The code for stack class:

```
#include <iostream>
#include "node.h"

using namespace std;
class Stack{
public:
    Node *topNodePtr;

    Stack(){
         topNodePtr = NULL;
    }

    void push(string data){
        Node *tempNodePtr = new Node(data);
        if(this->topNodePtr == NULL){
            topNodePtr = tempNodePtr;
        }
        else{
            tempNodePtr->next = topNodePtr;
            topNodePtr = tempNodePtr;
        }
    }

    void print(){
        if(this->topNodePtr == NULL){
            cout<<"The stack is empty right now select push     to add new Nodes to the stack\n";
        }
        else{
            Node *tempNodePtr;
            tempNodePtr = this->topNodePtr;
            cout << "NULL" <<endl;
            while(tempNodePtr != NULL){
                cout << "^" <<endl;
                cout << "|" <<endl;
                cout << tempNodePtr->data<<endl;
                tempNodePtr = tempNodePtr->next;
            }
        }   
    }
};

int main(){
cout << "Menu\n";
cout << "1. Push\n";
cout << "2. Print\n";
cout << "-1. Exit\n";
int n = -1;
cin >> n;
cout << "Select n : ";
Stack *s;
do{
    if(n == 1){
        string str;
        cout << "Enter data : ";
        cin >> str;
        s->push(str);
    }
    else if(n == 2){
           s->print();
    }
    else{
        cout << "Select smthng from the list\n";
    }
    cout << "Select n : ";
    cin >> n;
}while(n != -1);
return 0;
} 

```

The code for node class:

```
#include <iostream>
#include <string>
#include "node.h"

using namespace std;

Node::Node(string data){
this->data = data;
this->next = NULL;
}

```

The code for node.h :

```
#ifndef NODE_H
#define NODE_H
#include <string>

class Node{
public:
    std::string data;
    Node *next;
    Node(std::string data);
};
#endif

```