I have tried very much to write and read linked list in file but couldn't succeed. The file is written to successfully but my program cannot read the linked list from file.
This is my code:
case 2:
temp = first;
while (temp != NULL)
{
temp->output(temp);
temp = temp->next;
}
break;
case 3: // for write in file
fstream file;
file.open("group.dat", ios::app | ios::out | ios::in | ios::binary);
{
temp = first;
while (temp != NULL)
{
file.write(reinterpret_cast<char*>(&temp), sizeof(user));
temp = temp->next;
}
}
exit(-1);
case 4: // for Read from file
fstream file;
file.open("group.dat", ios::app | ios::out | ios::in | ios::binary);
file.seekg(0);
while (!file.eof())
{
file.read(reinterpret_cast<char*>(&temp), sizeof(user));
}