Hey all
Im having a problem writing to text files. I am able to read from 
them no problem but just cant write to it.

struct sScore {
        char cName[40];
        int score;
}TopTen[SCORES];


fstream OutFile;
OutFile.open("HighScore.txt",ios::in);
if (OutFile){
     while (!OutFile.eof())
     {
            OutFile >> TopTen[iNumber].cName;
            OutFile >> TopTen[iNumber].score;
            iNumber++;
      }
}
 

The above code works fine for taking in player name and score no 
prob but the below code, when im sending an amended topten back out 
to the txt, just clears the txt file completely

OutFile.open("HighScore.txt",ios::out);
if (OutFile)
{
      for (int i = 0; i < (iNumNames+1);i++)
      {
       OutFile << TopTen[i].cName << " " << TopTen[i].score << endl;
                         
      }
}
OutFile.close();

Now any help would be appreciated as im only starting out on C++ and 
am completely lost and confusd at this moment in time
cheers
g

Reply via email to