Link to home
Start Free TrialLog in
Avatar of aagc
aagc

asked on

Weird problem working with text files,can some one help?

ok, 1st thnx for read me.

the following is how the proggy read the file
fstream database;
database.open(filename,ios::in | ios::out);
  while (!database.eof())
  {
     database.getline(persona[cont].nombre,60,'\n');
     if(strlen(persona[cont].nombre)==0) {cont=0;break;}
     database.getline(persona[cont].telefono,20,'\n');
     database.getline(persona[cont].ciudad,30,'\n');
     database.getline(persona[cont].edad,10,'\n');
     cont++;
  }
database.close();

then this is how i save the file....

cont=0;
database.open(filename,ios::out);
database.seekg (0, ios::beg);
for(;cont<max;cont++)
   {
   database << persona[cont].nombre <<endl;
   database << persona[cont].telefono <<endl;
   database << persona[cont].ciudad << endl;
   database << persona[cont].edad <<endl;
   }
database.close();

well all that works fine when the proggy runs the 1st and 2nd time... but at the 3er time the file just get deleted well not deleted but all the data inside is missing :(...
i really need help.

Thnx again u guys.
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tinchos
tinchos

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: dpearson

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer