** File struct contains a string for name and unsigned int score and num correct **
fstream file;
File IO;
vector<File> IoS;
unsigned int k = 0;
file.open("highscores.txt", ios_base::in);
IoS.clear();
if(file.is_open())
{
while (!file.eof())
{
getline(file, IO.name, '\t');
file << IO.score;
file.ignore(INT_MAX, '\t');
file << IO.corr;
file.ignore(INT_MAX, '\n');
IoS.insert(IoS.begin() +k, IO);
//IoS.push_back(IO);
IO.corr = IO.score= NULL;
IO.name = "";
}
}
file.close();
bool insert = false;
for (int i = 0; i < IoS.size(); i++)
{
if (IoS[i].score <= playerscore )
{
insert = true;
k = i;
break;
}
}
IO.corr = numcorr;
IO.name = playername;
IO.score = playerscore;
IoS.insert(IoS.begin() +k, IO);
file.open("highscores.txt", ios_base::out );
if(file.is_open())
{
for (int i = 0; i < IoS.size(); i++)
{
if (i == IoS.size()-1)
{
file << IoS[i].name << '\t' << IoS[i].score << '\t' << IoS[i].corr;
}
else
{
file << IoS[i].name << '\t' << IoS[i].score << '\t' << IoS[i].corr << '\n';
}
}
}
file.close();

New Topic/Question
Reply



MultiQuote





|