高手们请进

tangcx 2003-10-18 05:33:15
#include<string>
#include<iostream>
#define Null 0
using namespace std;
struct student
{string name; /* defined data structure*/
int number;
int mark;
struct student *next;
}
struct student *delet( struct student *head) /*delete function*/
{ struct student *delet,*p1=head,*p2;
p2=p1;
cout<<"input the student number what you want to delete";
cin>>delet->number;
while((p1->number!=delet->number)&&(p1->number!=Null))
{p2=p1;p1=p1->next;}
if(p1->number=delet->number)
{if(p1==head) head=p1->next;
else p2->next=p1->next;
}
return(head);}

struct student *insert(struct student *head) /*insert function*/
{ struct student *insert,*p3=head,*p4;
p4=p3;
cout<<"input the data what you want to inser"<<endl;
cin>>insert->number>>insert->name>>insert->mark;
while((p3->number<insert->number)&&(p3->number!=Null))
{p4=p3;p3=p3->next;}
if(p3->number>insert->number)
{if(p3=head) head=insert;
else p4->next=insert;
insert->next=p3;}
else {p3->next=insert;insert->next=Null;};
return(head);}

void main() /*main function*/
{struct student *p,*p1,*head,*p2;
char ch;
for(int i=1;i<=3;i++) /*input the data*/
{ p=new struct student;
cin>>p->name>>p->number>>p->mark;
if(i==1) head=p;
else p1->next=p;
p1=p;
}
p1->next=Null;
p2=head;
cout<<"do you want to delete the data(y\n)"<<endl;

cin>>ch;
if((ch=='y')||(ch=='Y')) p2=delet(head); /* call the delete function*/
cout<<"do you want to insert the data(y\n)";
cin>>ch;
if((ch=='y')||(ch=='Y')) p2=insert(head); /* call the insert function*/

while(p2!=Null) /*output the data*/
{cout<<p2->name<<p2->number<<p2->mark<<endl;
p2=p2->next;}

}
函数编译时出现:
--------------------Configuration: program - Win32 Debug--------------------
Compiling...
program.cpp
F:\C++\program\program.cpp(11) : error C2236: unexpected 'struct' 'student'
Error executing cl.exe.

program.obj - 1 error(s), 0 warning(s)

以上的程序在C语言中肯定没问题(修改一下关键字)
但在C++即出现问题,为什么????
...全文
29 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangcx 2003-10-18
  • 打赏
  • 举报
回复
没经验就是没经验
谢谢zihan(子寒)
zihan 2003-10-18
  • 打赏
  • 举报
回复
struct student
{string name; /* defined data structure*/
int number;
int mark;
struct student *next;
};

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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