用结构体变量的引用作函数参数

 1 #include <iostream>
 2 #include <string.h>
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 struct Student
 6 {
 7     int num;
 8     string name;
 9     float score[3];
10 }
11 stu={12345,"Li Li",88,89,98};
12 
13 int main(int argc, char** argv) {
14     void print(Student &);
15     print(stu);
16     return 0;
17 }
18 
19 void print(Student &stud)
20 {
21     cout <<stud.num<<" "<<stud.name<<" "<<stud.score[0]<<" "<<stud.score[1]<<" "
22     <<stud.score[2]<<endl;
23 }

 

posted @ 2018-08-01 16:04  borter  阅读(1917)  评论(0编辑  收藏  举报