运行时没有错误,可是却无输出值ios
//2. 编写一个程序,输入用户的姓名和电话号码,按姓名的词典顺序排列后,输出用户的姓名和电话号码。
#include<iostream.h>
#include<string.h>
class pbook
{
private:
char *name;
char *phone;
public:
class pbook *next;
void paixu();
pbook(){}
pbook(char *s,char *p)
{
name=new char[strlen(s)+1];
strcpy(name,s);
phone=new char[strlen(p)+1];
strcpy(phone,p);
}
void output()
{
cout<<name<<" "<<phone<<endl;
}
~pbook()
{
delete []name;
delete []phone;
}
};
void pbook::paixu()
{
int i=0;
pbook *l,*s,*q;
l=new pbook;
q=new pbook;
//cout<<"输入名字"<<" ";
//cin>>l->name ;
l->next=NULL;
while(1)
{
q=l;
i=0;
s=new pbook;
cout<<"输入名字"<<" ";
cin>>s->name;
if(s->name[0]!='*')
{
while(s->name[i]!='/0' &&q->name[i]!='/0')
{
if(q->name[i]=s->name [i])
i++;
else
{
while(q->name[i] >s->name[i] )
q=q->next;
s->next =q->next;
q->next=s;
break;
}
}
}
else
{
delete s;
delete q;
delete l;
break;
}
}
q=l;
cout<<"输出用户的姓名和电话号码:/n";
while(q->next!=NULL)
{
cout<<"输入电话号码"<<" ";
cin>>q->phone ;
q->output ();
}
}
void main()
{
pbook p;
p.paixu ();
}spa