我收到一个错误:
1> Source.cpp 1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl saveToFile(char const * const,struct Task * const,int)" (?saveToFile@@YAXQBDQAUTask@@H@Z) 在函数中引用_main 1>C:\Users\Evan\Desktop\Coding Stuff\C++ 程序\CS162 HW\cs_162_hw_2\Debug\cs_162_hw_2.exe : 致命错误 LNK1120: 1 unresolved externals
它只发生在我尝试运行我的 saveToFile 函数时。这是该函数的代码:
void saveToFile(const char fileName[MAX_CHAR], const Task list[], int size)
{
ofstream out;
out.open(fileName);
if(!out)
{
cerr << "Fail to open " << fileName << " for writing!" << endl;
exit(1);
}
int index;
for(index=0; index < size; index++)
{
out << list[index].course << ';' << list[index].description << ';' << list[index].date << endl;
}
out.close();
}