You are here:

C++/doubt in pointers


i am basically reading a txt file and making a link list database.
i read all the elements in the file put it into a variable temp.
then i create a structure studentElement {
Student data;  // Student is a class containing student info like name,ssn ,age.
studentElement *next;
studentElement *database;

in the input file ,
now i transfer the temp to
studentElement *newstudent = new studentElement();
  newstudent->data= temp;
  newstudent->next = database;
  database= newstudent;
display is a member function of class Student .so here everything is displayed right on the terminal.

but when i use a write to output file function,
while (temp1!= NULL)
blah blah
then in the output file it shows just the last entry of the input file repeated 10 times because there are 10 entries in the input file.
the problem is that at a memory location ,the contents are gettin over written .
what do i do about it .
thnk you.

Hello Amrutha.
I will need to see your program before I can help you. I cannot tell what can be wrong from your high-level description. There could be many things wrong. For example, it is possible that temp is an allocated piece of memory, and the operator= of the Student class is simply storing a pointer to temp.

Please post the source code, and if possible, the input text file.

Best regards.


All Answers

Answers by Expert:

Ask Experts




No longer taking questions.


No longer taking questions.

No longer taking questions.

©2016 All rights reserved.