fstream object complications

Can someone please explain to me why when I initialize this array of structures there are additional characters that I have not inputted in the text file??

For now only use the first name for each student. I will work on how to use the get member function to include the last name latter.


for (index = 0; index < SIZE; index++)
{
//Display the players' names, numbers, and scores
cout << left << setw(25) << classroom[index].name;
file << left << setw(25) << classroom[index].name;

for (count = 0; count < classroom[index].day[count]; count++)
{
cout << setw(5) << classroom[index].day[count];
file << setw(5) << classroom[index].day[count];
}
cout << endl;
file << endl;
}
}
file.close();
return 0;
}
[/code]
Last edited on
Give some example of your input, your expected output and your real output please.
it is suppose to be something like:

Name Attendance
Mary p p p p p p p p p p
Joe p p p p p p p p p p
Paul p p p p p p p p p p

but what it is doing:

Name Attendance
Mary p p p p p p p p p H

Joe p p p p p p p p p G

Paul p p p p p p p p p G

It is so strange because I do not enter those letters at the end of the line. And they also change. Sometimes it just one letter, or a symbol, or a number. It wasn't doing this at first.
I would look closely at the following snippet.
for (count = 0; count < classroom[index].day[count]; count++)

And realize that count increments every time the loop executes, changing the condition variable.

thanks I see the mistake. Should be:

for (count = 0; count < 10; count++)

like I have in the input section

much appreciation!
Topic archived. No new replies allowed.