C++ 如何使用文件I/O c++;
首先,我试图创建一个文件并对其进行写入,但它不允许我使用“”。您收到的错误是因为需要为employee类定义一个输出运算符C++ 如何使用文件I/O c++;,c++,file-io,C++,File Io,首先,我试图创建一个文件并对其进行写入,但它不允许我使用“”。您收到的错误是因为需要为employee类定义一个输出运算符 ostream& operator<<(ostream& _os, const Employee& _e) { //do all the output as necessary: _os << _e.variable; } 您应该为您的班级员工提供以下好友功能: class Employee { public:
ostream& operator<<(ostream& _os, const Employee& _e) {
//do all the output as necessary: _os << _e.variable;
}
您应该为您的班级员工提供以下好友功能:
class Employee {
public:
//....
friend ostream& operator<<(ostream& _os, const Employee& _e);
friend istream& operator>>(istream& _is, Employee& _e);
//....
}
class员工{
公众:
//....
friend ostream&operator(istream&uIS、Employee&uE);
//....
}
您需要定义一个操作符@carlpett:
用于input@Ken:哇,我一定累了。今晚就不累了……你们班的Employee
overwriteoperator@pipin1289吗?我试着把这个操作符添加到我的函数中,现在它说这个操作符函数的参数太多了。@GamalielTellezOrtiz您应该使它成为类的朋友
函数,并且仍然在外部定义它。
istream& operator>>(istream& _is, Employee& _e) {
//get all the data: _is >> _e.variable;
}
class Employee {
public:
//....
friend ostream& operator<<(ostream& _os, const Employee& _e);
friend istream& operator>>(istream& _is, Employee& _e);
//....
}