我不断收到来自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> >&,"
表示" 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);
然后,您只需要调整声明以及函数调用参数即可使程序编译。
相关文章:
- 将无符号char*转换为std::istream*C++
- 如何在对<char>C++程序进行逆向工程的同时将 std::basic_string 转换为 Rust 可读值?
- 将函数参数"const char*"转换为"std::string_view"是
- std::string 构造函数如何处理固定大小的 char[]?
- 如何使用多次 memcpy 转换回 std::vector<unsigned char>?
- 在标准中,模板参数的语法在哪里定义,例如,'std::function<int(char)>'?
- 为什么从 char 转换为 std::byte 可能是未定义的行为?
- <char> 使用 Vulkan 映射内存时如何使用 std::vector 而不是 void**?
- 类型为 'std::map< char,int > 的 <Swig 对象的代理
- C++:将模板类型 char 转换为 std::string
- 有效地将数据加载到 std::vector 中<char>
- 为什么 char 可以在 std::array 中初始化为 nullptr,而不是单独初始化?
- 从 std::string 到 std::array<char,size> 的 memcopy 额外数据是否是一种未定义的行为?
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- 没有'str'成员在 GCC 和 Clang 'std::basic_ostream<char>',但 MSVC 没有问题
- 将"std::string {aka std::basic_string}"赋值中的不兼容类型<char>
- 将结构 std::memcpy 转换为具有足够容量的 std::vector 是未定义的行为<char>吗?
- 如何将 int 复制到 boost/std::char 数组?
- C++错误(将 wstring 转换为字符串):无法将参数 1 从 std::wchar_t 转换为 std::char
- std::char*值上的hash值,而不是内存地址上的