zl程序教程

您现在的位置是:首页 >  其他

当前栏目

用 #include <filename.h> 格式来引用标准库的头文件

标准 格式 gt 引用 lt include 头文件 filename
2023-09-14 09:12:04 时间

用 #include <filename.h> 格式来引用标准库的头文件(编译器将从 标准库目录开始搜索)。

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 
 5 
 6 using namespace std;
 7 
 8 //定义结构
 9 struct student {
10     char  name[10];
11     float   grade;
12 };
13 
14 //交换student类型的数据 
15 void swap(student &x,student &y)      //swap的参数为引用传递方式
16 {
17     student temp;
18     temp=x;
19     x=y;
20     y=temp;
21 }
22 
23 //返回student类型的引用,求优者 
24 student& max(student &x,student &y)      //swap的参数为引用传递方式
25 {
26     return (x.grade>y.grade?x:y);
27 }
28 
29 //显示student类型的数据 
30 void show(student &x)      //show的参数为引用传递方式
31 {
32    cout<<x.name<<"  "<<x.grade<<endl;
33 }
34 int main(int argc, char** argv) {
35     
36      student a={"ZhangHua",351.5},b={"WangJun",385};
37 
38     //显示a和b的数据
39     cout<<"a:";
40     show(a);
41     cout<<"b:";
42     show(b);
43     cout<<"------------------"<<endl;
44 
45     //交换a和b的数据,并显示
46     swap(a,b);    
47     cout<<"a:";
48 show(a);
49     cout<<"b:";
50 show(b);
51     cout<<"------------------"<<endl;
52 
53     //计算和显示成绩高者
54     student t=max(a,b);
55     cout<<"Max:";
56     show(t);
57     return 0;
58 }