for loop - C++ reading values into an array on XCode -


i can't figure out why following code doesn't output properly. it's supposed read name , grades an entry of array of students. reason, there phantom entries in between real entries, denoted lines in output don't have name preceding numbers.:

fin.open("data.txt"); ( int i=0 ; getline(fin, info[i].name) && (i<size) ; i++){     fin.clear();     fin >> info[i].quiz.gradeone;     fin >> info[i].quiz.gradetwo;     fin >> info[i].quiz.gradethree;     fin.clear();     numb++;     cout << info[i].name << info[i].quiz.gradeone << info[i].quiz.gradetwo           << info[i].quiz.gradethree << endl; } fin.close(); 

here's data:

jeramy puleo 45 99 101 liz kershaw 55 70 35 sherrill dykes 88 94 100 emmitt auclair 89 94 88 nana bassler 22 55 88 

and (wrong) output:

jeramy puleo 45 99 101  0 32767 0 liz kershaw 55 70 35  0 0 0 sherrill dykes 88 94 100  0 0 0 emmitt auclair 89 94 88  0 0 0 nana bassler 22 55 88 


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -