#include
#include
#include
using namespace std;
struct student
{
int no;
string name;
};
class studentarray
{
private:
student* p;
ifstream infile;
int count = 0;
student st;
int max_num = 3;
public:
studentarray(){}
friend istream& operator >>(istream& in, student& st);
friend ostream& operator <<(ostream& out, student& st);
studentarray(ifstream& in)
{
p = new student[max_num];
in >> st;
while (!in.eof())
{
p[count] = st;
count++;
in >> st;
if (count == max_num)
{
max_num = 2;
student q = new student[max_num];
for (int i = 0; i < count; i++) q[i] = p[i];
delete[]p;
p = q;
}
}
}
~studentarray()
{
ofstream outfile("d:\student.bat");
int i = 0;
while (i < count)
{
i++;
outfile << p[i];
}
outfile.close();
}
};
istream& operator >>(ifstream& in, student& st)
{
in >> st.no >> st.name;
return in;
}
ostream& operator <<(ostream& out, student& st)
{
out << st.no << " " << st.name << endl;
return out;
}
int main()
{
student st;
ifstream infile("d:\student.bat");
if (infile.fail())
{
cout << "请输入学生的学号与姓名,并用EOF结束输入" << endl;
ofstream outfile("d:\student.bat");
while ((cin >> st) != EOF)
{
outfile << st;
cin >> st;
}
cout << "您的数据已成功写入d:\student.dat,请重新打开本程序" << endl;
outfile.close();
infile.close();
}
else
{
studentarray array1(infile);
cout << "已成功读取数据文件!" << endl;
}
}
代码如上
编译器提示: 二进制">>"没有找到接受“student”类型的右操作数的运算符(或没有可接受的转换)
二进制“<<”: 没有找到接受“student”类型的右操作数的运算符(或没有可接受的转换)
诸如此类的提示有七八个,请问我的代码哪里有问题?