人生苦旅∞ 2021-03-27 17:21 采纳率: 80%
浏览 1426
已采纳

expected primary-expression before '}' token怎么解决?

#include<iostream>
using namespace std;
struct employee{
	int num;
	int age;
	char sex;
	employee *next;
};
employee *head,*head1;
employee *create(){
	employee *head,*p,*pend;
	char ch;
	head=NULL;
	cout<<"\t输入数据?(y/n)";cin>>ch;
	if(ch=='y'){
		p=new employee;
		cout<<"\t编号:";cin>>p->num;
		cout<<"\t年龄:";cin>>p->age;
		cout<<"\t性别:";cin>>p->sex;
	}
	else
	goto L0;
	while(ch=='y'){
		if(head==NULL)head=p;
		else pend->next=p;
		pend=p;
		cout<<"\t输入数据?(y/n)";cin>>ch;
		if(ch=='y'){
			p=new employee;
			cout<<"\t编号:";cin>>p->num;
		    cout<<"\t年龄:";cin>>p->age;
		    cout<<"\t性别:";cin>>p->sex;
		}
	}
	pend->next=NULL;
	L0:return head;
}
void show(employee *head)
{
	employee *p=head;
	if(!head){cout<<"\t空链表!"<<endl;goto L1; }
	cout<<"\t链表中的数据是:\n";
	while(p){
		cout<<'\t'<<p->num<<" "<<p->age<<" "<<p->sex<<endl;
		p=p->next;
	}
	L1:
}
employee *del(int bh){
	employee *p,*q;
	if(!head){
		cout<<"\t空链表!"<<endl;
		goto L2;
	}
	cout<<"\t找不到需要删除结点!"<<endl;
	L2:return(head);
}
int main(){
	int choice,bh;
	L:
		cout<<"\n\t\t键入操作选择\n"<<endl;
		cout<<"\t1建立单向链表"<<endl;
		cout<<"\t2显示链表里员工信息"<<endl;
		cout<<"\t3删除指定编号结点"<<endl;
		cout<<"\t0退出"<<endl;
		cout<<"\t\t";
		cin>>choice;
		switch(choice){
			case 1:head=create();goto L;
			case 2:show(head);goto L;
			case 3:cout<<"\t输入编号:";
			       cin>>bh;
			       head=del(bh);goto L;
			case 0:cout<<"\t退出运行\n"<<endl;break;
			default:cout<<"\t输入错误,重新输入\n"<<endl;goto L;
		}
}

问题是第48行显示链表所有数据那里出错,一直提示expected primary-expression before '}' token

  • 写回答

2条回答 默认 最新

  • 猫叔大鸭梨 2021-03-27 21:03
    关注

    goto后面不需要执行什么东西的话47行后面 加个分号

    还有个问题是phead要和13行的head一样初始化一下。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度