问一个菜鸟问题~~~指针
#include<iostream>#include<string>
using namespace std;
class book
{
public:
int num;
float price;
book *next;
};
book *head=NULL;
bool check(string str)
{
for(int i=0;i<str.length();i++)
{
if((str[i]>'9'||str[i]<'0')&&str[i]!='.')
{
return false;
}
}
return true;
}
book * recat()
{
book *p1,*p2;
p1= new book;
head=p1;
p2=p1;
cout<<"请输入图书编号,以0结束!"<<endl;
string str;
cin>>str;
while(!check(str))
{
cout<<"输入的不是数字!请重新输入!"<<endl;
cin>>str;
}
p1->num=atoi(str.c_str());
if(0!=p1->num)
{
cout<<"请输入价格:"<<endl;
cin>>str;
while(!check(str))
{
cout<<"输入的不是数字!请重新输入!"<<endl;
cin>>str;
}
p1->price=atoi(str.c_str());
//cin>>p1->price;
}
else
{
delete p1; p2=NULL;head=NULL;return head;
}
while(0!=p1->num)
{
p2=p1;
p1= new book;
cout<<"请输入图书编号,以0结束!"<<endl;
cin>>str;
while(!check(str))
{
cout<<"输入的不是数字!请重新输入!"<<endl;
cin>>str;
}
p1->num=atoi(str.c_str());
if(0!=p1->num)
{
cout<<"请输入价格:"<<endl;
cin>>str;
while(!check(str))
{
cout<<"输入的不是数字!请重新输入!"<<endl;
cin>>str;
}
p1->price=atoi(str.c_str());
//cin>>p1->price;
}
p2->next=p1;
}
delete p1; p2->next=NULL;
return head;
}
void showbook(book*head);
{
cout<<endl;
cout<<"图书信息如下:"<<endl;
while(head)
{
cout<<"图书编号:"<<head->num<<"\t";
cout<<"图书价格:"<<head->price<<endl;
head=head->next;
}
}
void main()
{
book *head=NULL;
head=recat();
showbook(head);
}
//////////////////////////////////////////////////////
H:\temp\vc6++\ee\ww.cpp(86) : error C2447: missing function header (old-style formal list?)
执行 cl.exe 时出错.
不知道 怎么 改~~ 求指教!!!