2017-11-09 2 views
-1

내 프로그램의이 부분은 학생의 이름과 성적 목록을 읽은 다음 평균하여 함께 표시합니다. 텍스트 파일에서파일의 텍스트가 배열로 읽지 않습니다.

int loadStudentNamesGrades(string students[], 
          int grades[][MAX_GRADES], 
          string fileName, 
          int maxStudents) 
{ 
    ifstream inFile; // input file stream 
    string nameFile; // name of file 
    string studentName; // name of student 
    int numStudents = 0; // number of students initialized to 0 

    inFile.open(fileName); // open the file 
    if (!inFile) 
    { 
     cout << "Unable to Open File!\n"; 
     system("PAUSE"); 
     exit (EXIT_FAILURE); 
    } 

    for (int i = 0; i < maxStudents && (inFile >> studentName >> numStudents); 
      i++, numStudents++) 
    { 
     for (int j = 0; j < MAX_GRADES; j++) 
     { 
      inFile >> grades[i][j]; 
     } 

     students[i] = studentName; 
    } 

    inFile.close(); 

    return numStudents; 
} 

내 프로그램을 실행하려고, 내 메뉴 표시되지만 값 없음 : 여기 int loadStudentNamesGrades(string students[], int grades[][MAX_GRADES], string fileName, int maxStudents);


은 정의입니다 :

나는 같은 기능을 선언 채우다. 내가 아는 한 내 오류는 반환되지 않기 때문에 파일이 제대로 열리고 있습니다.

+0

관련 없음 : 'i'와 'numStudents'의 차이점은 무엇입니까? 아마 둘을 결합 할 수 있습니다. – user4581301

+0

디버거를 사용하여 단계별 실행 시도 – pm100

답변

0

배열을 읽는 것처럼 보이지만 그 배열을 반환하지는 않습니다. 이 같은 참조 뭔가를 당신의 배열을 전달하십시오 :

int loadStudentNamesGrades(string (&students)[10], int (&grades)[10][MAX_GRADES], 
          string fileName, int maxStudents) 

당신은 대신 배열의 vector의 사용에 대한 생각 할 수있다.

관련 문제