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

用 #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 }

原文地址:https://www.cnblogs.com/borter/p/9412899.html

时间: 2024-08-25 11:18:27

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

用 #include “filename.h” 格式来引用非标准库的头文件

用 #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 using namespace std; 5 //参数带有默认值的函数 6 disp(

windows与linux 标准c语言头文件

C语言符合标准的头文件#include <assert.h> //设定插入点 #include <ctype.h> //字符处理 #include <errno.h> //定义错误码 #include <float.h> //浮点数处理 #include <fstream.h> //文件输入/输出 #include <iomanip.h> //参数化输入/输出 #include <iostream.h> //数据流输入/输

C基础-标准C语言头文件

标准C语言头文件 ISO C标准定义的头文件(24项) <assert.h> 验证程序断言 <complex.h> 支持复数算术运算 <ctype.h> 字符类型 <errno.h> 出错码 <fenv.h> 浮点环境 <float.h> 浮点常量 <inttypes.h> 整型格式转换 <iso646.h> 替代关系操作符宏 <limits.h> 实现常量 <locale.h> 局部类

C++ 引用#include&lt;math.h&gt; 找不到动态库

问题: 使用g++ 编译C++文件报错了,无法识别abs,可是我这文件中已经添加了#include<math.h>? 于是在指令中加入-lm g++ main.cpp AStar.cpp -lm -std=c++11 -o astar 可是问题并没有解决,还是同样的问题. 查看usr/lib 下是否有libm.so,发现在/usr/lib/x86_64-linux-gnu路径下,于是拷贝到usr/lib路径下,再次执行,依然没有解决问题. 最后发现是没有引用standard library标准

#include、#import与@class的使用与头文件循环引用问题

#include #include <>:通常是对系统库文件的引用,编译器会去系统文件目录下查找. #include "xxx.h":通常是对自定义文件的引用,编译器首先会去用户目录下查找,然后再去安装目录查找,最后去系统文件目录查找. #import #import的功能与#include差不多,但是可以解决头文件重复导入的问题,而#include会有重复导入头文件的问题, 比如class文件A.B都引用了class C,如果class D引用了class A.B,这时候

c/c++标准库中的文件操作总结

1 stdio.h是c标准库中的标准输入输出库 2 在c++中调用的方法 直接调用即可,但是最好在函数名前面加上::,以示区分类的内部函数和c标准库函数. 3 c标准输入输出库的使用 3.1 核心结构体 FILE结构体 打开一个文件的时候获取它,然后就可以不用管它了. 3.2 核心方法 3.2.1 fopen 第一个字符串是文件的路径. 第二个参数是一个字符串,表示操作该文件的模式,"rb"表示read binary,即以二进制的形式来读该文件. 3.2.2 fseek 第一个参数是F

C和C++中include 搜索路径的一般形式以及gcc搜索头文件的路径

C和C++头文件的一些想法 1. 是对于include""  搜索的路径 2. 在导入库的一些想法 C和C++头文件的一些想法,布布扣,bubuko.com

标准C++常用头文件及描述

#include <algorithm> //STL 通用算法 #include <bitset> //STL 位集容器 #include <cctype> //字符处理 #include <cerrno> //定义错误码 #include <cfloat> //浮点数处理 #include <ciso646> //对应各种运算符的宏 #include <climits> //定义各种数据类型最值的常量 #include

python标准库之shutil文件

import shutil,glob,os#作用:处理一些文件操作,如复制,设置权限#复制文件copyfile()将源内容复制到目标,如果没有权限写目标文件则产生 ioerrorprint 'before:',glob.glob('*.txt')shutil.copyfile('lorem.txt',r'copy/lorem.txt')print 'after:',glob.glob(r'copy/lorem.txt')#由于这个函数会打开输入文件进行读取,而不论其类型,所以某些特殊文件(如un