如下c++说我很多函数定义不合法,请问该咋办?

int main()
{

int choose;
student v;
do{
menu();
cin>>choose;
switch(choose)
{
case1:v.insert();break;
case2:v.display();break;
case3:v.locate();break;
case4:v.modify();break;
case5:v.save();break;
case6:v.load();break;
default:break;}

}
while(choose!=0);
}

慕勒3428872
浏览 255回答 3
3回答

慕神8447489

void menu() { .... } //如果要将menu写在main后面,这里加:void menu();void insert();void display();void locate();void modify();void save(); //类似这样将要调用的函数头写在这个位置即可int main() { int choose; student v;do {  menu(); cin>>choose;  switch(choose) {case1:v.insert();break;case2:v.display();break;case3:v.locate();break;case4:v.modify();break;case5:v.save();break;case6:v.load();break;default:break;}}while(choose!=0);}

茅侃侃

c++标准不允许在一个函数内部定义另一个函数

浮云间

你的serch函数定义都写到main里面去了,不缩进看不出来吧应该是这样#include <iostream>#include <fstream>#include <string>using namespace std;class student{ public: string name; string id; string rage; string chinese; int chinesenum; string math; int mathnum; string english; int englishnum; student *next; };void serch( student *a ){ string *rage2; cout << "输入籍贯" << endl; cin >> *rage2; int i = 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 );}
打开App,查看更多内容
随时随地看视频慕课网APP