Reading txt File into Linked List Problems [C++], HELP ME PLEASE.. (C++)

Greetings to All Si Fu here.. I'm facing problem in reading data from txt file and put them into linked list..

My function for the loading file is :

void SMAS::load_file() //load database to system from txt file
{
nodetype *newnode = new nodetype;//create a new node
head = NULL;

ifstream input("list.txt");//read from file named list

string nIC;
string nNAME;
string nCONTACT;
string nEMAIL;
int nAGE;
string nSTATUS;
string nREASON;

if(input.fail()) //if file did not exist
{
cout << "fail"<<endl;
return;
}
else
{
cout << "SUCCESS"<<endl;
while(!input.eof()) //if file not end of file
{
//read data from txt file named list
getline(input, nIC);
cout << nIC <<endl;
getline(input, nNAME);
cout << nNAME <<endl;
getline(input, nCONTACT);
cout << nCONTACT <<endl;
getline(input, nEMAIL);
cout << nEMAIL <<endl;
input >> nAGE;
cout << nAGE <<endl;
getline(input, nSTATUS);
cout << nSTATUS <<endl;
getline(input, nREASON);
cout << nREASON << endl;

nIC = newnode -> IC;
nNAME = newnode -> NAME;
nCONTACT = newnode -> CONTACT;
nEMAIL = newnode -> EMAIL;
nAGE = newnode -> AGE;
nSTATUS = newnode -> STATUS;
nREASON = newnode -> REASON;

if(head == NULL)//if head is NULL
{
head = newnode;
head -> link = NULL;
}
else
{
nodetype *current = head;
while( current -> link != NULL)
current = current -> link;

current -> link = newnode;
current -> link -> link = NULL;
}
}

input.close(); //close file
}
}

I can cout the data but got some weird numbers at the backpart like 1053567757. I'm wondering what is that. and i couldn't insert those data back into linked list. Is there any problem with my code ? how to i correct it ? Thanks all for spending some time in my post..
Is there any problem with my code ?
The first problem is the time when you check the error of the read data. Imagine you have just one data set:
You read that data set and everything is fine (not eof). Now you try to read the second non existing data set. The first getline() emits an error but you don't care and store the non existing data.

The solution is that you first read the data and create the node only when there's no error.


The second problem is: This nIC = newnode -> IC; and following overwrite the read data. AGE isn't initialized and so you always get a random number
im using OOP.. using class object. linked list data type. each nodes i saved customer details. but i coulnt read it from txt file. it will appear windows explorer not responding .. not compilation error. i believe that is my linked list there got error. how ? sifu sifu..
no1 can help out this C++ program?
can u show how data was written into file?
what about my previous post?
I think nvm ba. my assignment gonna due very soon and i need to proceed with documentation. still need prepare for viva. i think i just used save file function will do as backup. the load file i omit. thanks everyone spending your time reading my post. appreciate much
Topic archived. No new replies allowed.