problem clearing the buffer

I don't understand why temp name is making itself back to "" after
tempScore and tempName aren't being assigned correctly either.
I am trying to read scores from a file into a linked list, then insert
a score in the correct spot in the link. My file reader seems to be working
but i just read and output. Also, sometimes i feel like it reads past info that
i've gotten scores on, like the buffer isn't clearing.
ScorePtr is a typedef HighScores*

void saveScores(int score, string name)
{
ScorePtr head;
string tempScore;
string tempName;
int tempScoreInt;
ScorePtr newNode;
ScorePtr current;
ScorePtr tail;
HighScores newScore;
string junk = "";
newScore.name = name;
newScore.score = score;
newScore.link = NULL;
ifstream fin;

fin.open("High Scores.txt");
//getline(fin, junk);
getline(fin, tempName);
fin >> tempScoreInt;
cout << tempName;
cout << tempScoreInt;
head = getNode(tempScoreInt, tempName);
tail = head;

do
{
getline(fin, tempName);
if(tempScore != "none")
{
fin >> tempScore;
if(tempName != "none")
{
newNode = getNode(tempScoreInt, tempName);
tail->link = newNode;
tail = newNode;
}
}
}while(tempName != "none");
}
Last edited on
Also, sometimes i feel like it reads past info that i've gotten scores on, like the buffer isn't clearing.
I don't understand. Post an example.
You are discarding `tempScore' value.

Also, getline() may give you issues, when remains a '\n' in the buffer.
Topic archived. No new replies allowed.