linked list simple

Hello everyone I am trying to print the linked list but I keep getting error can someone just point out the mistake? I just cannot see it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
struct Personnode
{

	int data()
	{
			return data_field;
	}
	Personnode* link()
	{
		return link_field;
	}

	int data_field;
	Personnode* link_field;
};
int main ()
{
	int SSNumber;
	Personnode* ptr;
	Personnode* head = NULL;
	cout << "Id " << endl;
	cin >> SSNumber;
	while(cin)
	{
		ptr = new Personnode;
		ptr ->  data_field = SSNumber;
		ptr -> link_field = head;
		
		cout << "id" << endl;
		cin >> SSNumber;
	}
	ptr = head;
	cout << "print " << endl;
	
	
	while (ptr != NULL)
	{
		cout << ptr -> data();
		ptr = ptr->link();
	}
	cout << endl;
	system("pause");
	return 0;
}
found out just had to add head = ptr;
Topic archived. No new replies allowed.