c++总是说serch这个函数定义的不合法,这是问什么
发布网友
发布时间:2022-05-11 12:31
我来回答
共2个回答
热心网友
时间:2023-10-12 13:20
你的serch函数定义都写到main里面去了,不缩进看不出来吧。。。
应该是这样
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class student
{ public:
stringname;
stringid;
stringrage;
stringchinese;
intchinesenum;
stringmath;
intmathnum;
stringenglish;
intenglishnum;
student*next;
};
void serch( student *a )
{
string *rage2;
cout << "输入籍贯" << endl;
cin >> *rage2;
inti = 0;
student *n;
n = a;
while ( n )
{
if ( !strcmp( n->rage, *rage2.c_str() ) )
i++;
n = n->next;
}
cout << rage2 << "有" << i << "人" << endl;
}
void main()
{
student *head;
student *p = new student;
head = p;
student *q = new student;
fstream iflie( "input.txt", ios::in | ios::binary );
while ( iflie.peek() != EOF )
{
iflie >> p->name >> p->id >> p->rage >> p->chinese >> p->chinesenum >> p->math >> p->mathnum >> p->english >>
p->englishnum;
cout<< p->name << ' ' << p->id << ' ' << p->rage << ' ' << p->chinese << ' ' << p->chinesenum << ' ' << p->math << ' ' << p->mathnum
<< ' ' << p->english << ' ' << p->englishnum << endl;
p->next = q;
p= q;
q= new student;
}
iflie.close();
delete p;
delete q;
serch( head );
}
热心网友
时间:2023-10-12 13:21
serch是一个函数,main是一个函数,c++标准不允许在一个函数内部定义另一个函数