#Using Struct to take data from txt file

19 messages · Page 1 of 1 (latest)

blissful ospreyBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

frozen parcel
#
 fstream infile;
  infile.open("StudentScores.txt");
  
  if(infile.is_open()){
     cout << "File Opened!" << endl;
  } else {
    cout << "Error opening file!" << endl;
  }
  
  while(!infile.eof()) {
    cout << "In Loop!" << endl;
    
    numStudents++;
    
    cin >> studentList[numStudents].name >> studentList[numStudents].score;

    cout << "SET" << studentList[numStudents].name << studentList[numStudents].score;

    if (studentList[numStudents].score > maxScore){
      maxScore = studentList[numStudents].score;
      cout << "maxscore" << studentList[numStudents].score;
    } 
    
    totalScore = totalScore + studentList[numStudents].score;
    cout << totalScore << endl;
  }
  
  infile.close();```
#

im getting the "File Opened!" cout and the "In Loop!" cout but not the set or any of the others

unique ridge
#

idk, not enough info

#

no main function, can't compile and run it

#

what is studentList, where does it come from, what does it look like

#

what is totalScore, all the same questions

#

I can guess at some of this stuff

#

but I don't want to guess

#

it's not reasonable to ask us to guess

frozen parcel
#

yeah my bad

unique ridge
#

even if I guess, maybe you made a typo

frozen parcel
#

okay so basically the struct im using is

#
struct student
{
  string name;
  int score;
};```
unique ridge
#

I don't want "basically"

#

just post reasonably complete code

#

or you could copy paste the contents of your data into a stringstream such that you can reproduce it here with the server bot