求助!!郁闷死了!error c2679

flyzly 2008-06-02 09:50:45
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<iomanip.h>
struct student
{
char name[20];
float height;
student *next;
};
void main()
{
student a[100];
int i;
cout<<"请输入: 姓名 身高\n ";
for(i=0;i<100;i++)
{
cin>>a[i].name>>a[i].height;
a[i].next=NULL;
}
ofstream fout("student.txt");
if(!fout)
cout<<"文件打开失败!\n";
for(i=0;i<100;i++)
fout<<a[i].name<<" "<<a[i].height<<" "<<a[i].next<<endl;
fout.close();
ifstream fin("student.txt");
if(!fin)
{
cout<<"文件打开失败\n";
return;
}
student b[100];
i=0;
while(fin>>b[i].name>>b[i].height>>b[i].next)
i++;
student *head;
int j;
head=b;
for(i=1;i<100;i++)
{
if(head->height<b[i]->height)
{
b[i].next=head;
head=&b[j];
}
for(j=0;j<i;j++)
{
if(b[j].height<b[i].height)
{
b[i].next=b[j].next;
b[j].next=&b[i];
break;
}
b[j-1].next=&b[i];
}
}
cout<<setw(20)<<"姓名"<<setw(12)<<"身高"<<endl;
student *p;
p=head;
do
{
cout<<setw(20)<<p->name<<setw(12)<<p->height<<endl;
p=p->next;
}while(p!=NULL)
fin.close();
ifstream fin("student.txt");
if(!fin)
cout<<"文件打开失败\n";

char temp[20];
cout<<"请输入要查找的人姓名:";
cin>>temp;
student s;
while(fin>>s.name>>s.height>>s.next)
{
int k;
k=stricmp(s.name,temp);
if(k==0)
{
cout<<s.name<<s.height;
break;
}
if(k!=0)
cout<<"查无此人\n";




}
提示出错
--------------------Configuration: temp2 - Win32 Debug--------------------
Compiling...
a.cpp
D:\Cheung\阅读器\temp2\a.cpp(35) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'struct student *' (or there is no acceptable conversion)
D:\Cheung\阅读器\temp2\a.cpp(35) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.

a.obj - 1 error(s), 0 warning(s)
...全文
98 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xajnewuser 2008-06-02
  • 打赏
  • 举报
回复
while(fin>>b[i].name>>b[i].height>>b[i].next)
没调试出来,暂时还不知怎么修改
Chivalry 2008-06-02
  • 打赏
  • 举报
回复
while(fin>>b[i].name>>b[i].height>>(char*)b[i].next) 
i++;
ouyh12345 2008-06-02
  • 打赏
  • 举报
回复
重载>>,以接收参数为student *
flyzly 2008-06-02
  • 打赏
  • 举报
回复
这个是我改好后的
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<iomanip.h>
struct stu
{
char name[20];
float height;
stu *next;
};
void main()
{
stu a[100];
int i,j=0;
cout<<"姓名 身高\n";
for(i=0;i<100;i++)
cin>>a[i].name>>a[i].height;
ofstream fout("stu.txt");
if(!fout)
cout<<"文件打开失败\n";
for(i=0;i<100;i++)
fout<<a[i].name<<" "<<a[i].height<<endl;
fout.close();
ifstream fin("stu.txt");
if(!fin)
cout<<"文件打开失败\n";
stu b[100];
for(i=0;i<100;i++)
{
fin>>b[i].name>>b[i].height;
b[i].next=NULL;
}
fin.close ();
stu *head,*p,*temp;
head=b;
for(i=1;i<100;i++)
{
if(head->height<b[i].height)
{
b[i].next=head;
head=&b[i];
}
else
{
p=head;temp=head;
while(p!=NULL)
{
if(b[i].height>p->height)
{
temp->next=&b[i];
b[i].next=p;
j=1;
break;
}
else
{
temp=p;
p=p->next;
}
}
if(p==NULL)
temp->next=&b[i];

}
}
//输出
p=head;
cout<<setw(20)<<"姓名"<<setw(12)<<"身高\n";
while(p!=NULL)
{
cout<<setw(20)<<p->name<<setw(12)<<p->height<<endl;
p=p->next;
}
//查找
char x[20];
cout<<"输入要查找的人姓名:";
cin>>x;
p=head;
while(p!=NULL)
{
int y=stricmp(x,p->name);
if(y==0)
{
cout<<setw(20)<<"姓名"<<setw(12)<<"身高\n"
<<setw(20)<<p->name<<setw(12)<<p->height<<endl;
break;
}
else
p=p->next;
}
if(p==NULL)
cout<<"查无此人\n";

}
flyzly 2008-06-02
  • 打赏
  • 举报
回复
谢谢大家,我知道为什么了
b[i].next的问题,我把它写入student.txt之后在读出来的时候出错了
结构体成员next是指针属性,读出的时候出错了

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧