表示“Apple Mach-O Linker(Id)Error“readIt(std::_ 1::basic_ifstream>&,”)的
有人看到它不断卡住的错误吗?非常感谢!
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
//PERRYI
// following: student's name, two test grades and final exam grade.
// It then prints this information to the screen.
const int NAMESIZE = 15;
const int MAXRECORDS = 50;
struct Grades // declares a structure
{
char name[NAMESIZE + 1];
int test1;
int test2;
int final;
char letter;
};
typedef Grades gradeType[MAXRECORDS];
void readIt (ifstream&,Grades [], int []);
int main()
{
ifstream indata;
indata.open("graderoll.txt");
int numRecord; // number of records read in
gradeType studentRecord;
if(!indata)
{
cout << "Error opening file. \n";
cout << "It may not exist where indicated" << endl;
return 1;
}
readIt(indata,studentRecord,&numRecord); // FILL IN THE CODE TO CALL THE FUNCTION ReadIt.
// output the information
for (int count = 0; count < numRecord; count++)
{
cout << studentRecord[count].name << setw(10)
<< studentRecord[count].test1
<< setw(10) << studentRecord[count].test2;
cout << setw(10) << studentRecord[count].final << endl;
}
return 0;
}
void readIt( ifstream& inData, Grades gradeRec[], int& total)
{
total = 0;
inData.get(gradeRec[total].name, NAMESIZE);
while (inData)
{
inData >> gradeRec[total].test1;// FILL IN THE CODE TO READ test1
inData >> gradeRec[total].test2;// FILL IN THE CODE TO READ test2
inData >> gradeRec[total].final;// FILL IN THE CODE TO READ final
total++; // add one to total
inData.ignore(81,'\n');// FILL IN THE CODE TO CONSUME THE END OF LINE
inData >> gradeRec[total].name;
total = (gradeRec[total].test1 + gradeRec[total].test2)*(.30) + (gradeRec[total].final * .40);
if (total <= 100 || total >= 90 )
cout << "A";
else if (total <= 89 || total >= 80)
cout << "B";
else if (total <= 79 || total >= 70)
cout << "C";
else if (total <= 69 || total >= 60)
cout << "D";
else
cout << "F";
}
}
有人看到它不断卡住的错误吗?非常感谢!
最佳答案
您的原型(prototype)void readIt (ifstream&,Grades [], int []);
与您的函数void readIt( ifstream& inData, Grades gradeRec[], int& total)
不匹配。参数类型必须完全匹配。