在此先感谢您的帮助!该计划是一项学生注册计划。C++ ostream:没有运算符匹配<<&期望的初始值设定符&'token'
输入是通过文件,结果输出到文件。然后一般的想法是学习C++,方法重载 - 包括运算符和fstream
的。我会发布编译器指向的代码,但请让我知道如果你想看到其他代码。
当我去编译错误点到我的头文件方法,在我的课外,但在#endif
内。见下文。
std::ostream & operator << (std::ostream & os, const Registration & R);
这个文件的实现是这样的:
std::ostream &operator <<(std::ostream & os, const Registration & R )
{ os << "Student ID: " << R.GetStudentId() << "\n"
<< "Semester: " << R.GetSemester() << "\n \n";
for(unsigned i = 0; i < R.GetCount(); i++)
{
os << "\tUnit Name : " << R.GetName(i) << "\n"
<< "\tUnit Id : " << R.GetId(i) << "\n"
<< "\tCredit Points : " << R.GetCredits(i) << "\n"
<< "\tStudent Mark : " << R.GetResult(i) << "\n"
<< "\tDate : " << R.GetDay(i) << " " << R.GetMonth(i) << " " << R.GetYear(i) << "\n\n";
}
os << "Total Credits :" << R.GetCredits() << "\n"
<< "Number of Units : " << R.GetCount() << "\n"
<< "Average Mark : " << R.GetAverage();
return os;
}
而且main()中再次
int main()
{
ifstream infile("rinput.txt");
if(!infile) return -1;
Registration R;
infile >> R;
ofstream ofile("routput.txt");
ofile << R; // Error Here RE- no match for 'operator<<'
cout << "\nComputation completed. Check output file. \n";
return 0;
}
感谢您的任何和所有帮助,希望这不是一个新秀错误...我在哪里迟到了。
编辑:我在所有的头文件中都使用了“using namespace std”#& #include。
你忘了'#include'。 –
2015-04-01 16:59:06
@Kerrek - 在我所有的头文件中都有:) – 2015-04-01 17:04:55
@MasterSketchiggle请发布[MCVE](http://stackoverflow.com/help/mcve),让每个人都能重现你的错误。 – 2015-04-01 17:14:58