亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如下c++說我很多函數定義不合法,請問該咋辦?

如下c++說我很多函數定義不合法,請問該咋辦?

C++ C
慕勒3428872 2022-06-03 09:09:47
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);}
查看完整描述

3 回答

?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

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);
}



查看完整回答
反對 回復 2022-06-06
?
茅侃侃

TA貢獻1842條經驗 獲得超22個贊

c++標準不允許在一個函數內部定義另一個函數

查看完整回答
反對 回復 2022-06-06
?
浮云間

TA貢獻1829條經驗 獲得超4個贊

你的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 );}


查看完整回答
反對 回復 2022-06-06
  • 3 回答
  • 0 關注
  • 203 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號