我不断收到来自Xcode的错误,说" Apple Mach-O Linker (Id) Error "readIt(std::_1::basic_ifstream<char,std::_1::c

I keep getting an error from Xcode that says " Apple Mach-O Linker (Id) Error "readIt(std::_1::basic_ifstream<char,std::_1::char_traits<char> >&,"

本文关键字:std char readIt Error lt ifstream basic Linker Xcode Mach-O Apple      更新时间:2023-10-16

表示" 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";


      }
  }

有没有人看到它一直卡住的错误?非常感谢!

您的原型void readIt (ifstream&,Grades [], int []);与您的函数不匹配void readIt( ifstream& inData, Grades gradeRec[], int& total)。 参数类型必须完全匹配。

正如 rafeek 刚刚指出的,原型和函数声明必须匹配。如果你的函数原型是这样的:void readIt(ifstream& inData, Grades gradeRec[], int& total);然后,您只需要调整声明以及函数调用参数即可使程序编译。

相关文章: