c++头文件

转载来源:https://zhidao.baidu.com/question/98945525.html

转载来源:https://zhidao.baidu.com/question/590920462.html

常用的一些头文件:

  • #include <iostream.h> //数据流输入/输出

iostream.h是input output stream的简写,意思为标准的输入输出流头文件。它包含:

<span style="color:#333333">  (1)cin>>"要输入的内容"</span>

(2)cout<<"要输出的内容"

iostream.h与iostream是不同的。

  #include<iostream.h>是在旧的标准C++中使用。在新标准中,用#include<iostream>。iostream 的意思是输入输出流。#include<iostream>是标准的C++头文件,任何符合标准的C++开发环境都有这个头文件。还要注意的是:在VS编程时要添加:
  using namespace std;
  其原因是:后缀为.h的头文件C++标准已经明确提出不支持了,早些的实现将标准库功能定义在全局空间里,声明在带.h后缀的头文件里,C++标准为了和C区别开,也为了正确使用命名空间,规定头文件不使用后缀.h。因此,当使用<iostream.h>时,相当于在c中调用库函数,使用的是全局命名空间,也就是早期的c++实现;当使用<iostream>的时候,该头文件没有定义全局命名空间,必须使用namespace std;这样才能正确使用coutC++开发环境都有这个头文件。还要注意的是:在VS编程时要添加:
  using namespace std;
  其原因是:后缀为.h的头文件C++标准已经明确提出不支持了,早些的实现将标准库功能定义在全局空间里,声明在带.h后缀的头文件里,C++标准为了和C区别开,也为了正确使用命名空间,规定头文件不使用后缀.h。因此,当使用<iostream.h>时,相当于在c中调用库函数,使用的是全局命名空间,也就是早期的c++实现;当使用<iostream>的时候,该头文件没有定义全局命名空间,必须使用namespace std;这样才能正确使用cout
  • #include <math.h> //定义数学函数
math.h文件中声明了常用的一些数学运算,比如三角函数、反三角函数、双曲三角函数、指数与对数、取整与取余、绝对值、标准化浮点数等等。文件中声明了常用的一些数学运算,比如三角函数、反三角函数、双曲三角函数、指数与对数、取整与取余、绝对值、标准化浮点数等等。
  • #include <stdio.h> //定义输入/输出函数

#include<stdio.h>是在程序编译之前要处理的内容,称为编译预处理命令。编译预处理命令还有很多,它们都以“#”开头,并且不用分号结尾。

在使用标准函数库中的输入输出函数时,编译系统要求程序提供有关的信息(例如对这些输入输出函数的声明),#include<stdio.h>的作用就是用来提供这些信息的,stdio.h是C编译系统提供的一个文件名,stdio是“standard input & output”的缩写,即有关标准输入输出的信息。

在程序中用到系统提供的标准函数库中的输入输出函数时,应在程序的开头写上一行:#include"stdio.h"或者是#include<stdio.h>,这样才能调用库函数。二者主要在于查找效率上有差别,#include<stdio.h>一般用包含系统文件,它是查找先从系统目录查找开始查找;#include "stdio.h"一般用包含项目文件,它是查找先从项目目录查找开始查找。

在编写C语言中,常用到printf()和scanf()函数,他们就是stdio.h中的两个标准输入输出函数,所以编程语句中如果要用到此两个函数就一定要在头文件中加入#include<stdio.h>。

  • #include <string.h> //字符串处理

C++中,string头文件基本上已经包含在iostream中了。

但是,平时使用的时候建议加上#include<string.h>(尤其在以下情况下)
1、使用string类
2、使用cin、cout语句来输入输出string类型变量(注意,同时还需要#include<sstream>)
3、使用memset()、strlen()、strcpy()等函数时。
1、使用string类
2、使用cin、cout语句来输入输出string类型变量(注意,同时还需要#include<sstream>)
3、使用memset()、strlen()、strcpy()等函数时。
  • #include <stdlib.h> //定义杂项函数及内存分配函数
<span style="color:#333333"><span style="color:#333333"><span style="color:#333333">stdlib 头文件即standard library标准库头文件</span></span><span style="color:#333333">。stdlib.h里面定义了五种类型、一些宏和通用工具函数。 类型例如</span><a data-cke-saved-href="https://baike.baidu.com/item/size_t" href="https://baike.baidu.com/item/size_t">size_t</a><span style="color:#333333">、wchar_t、div_t、ldiv_t和lldiv_t; 宏例如EXIT_FAILURE、EXIT_SUCCESS、</span><a data-cke-saved-href="https://baike.baidu.com/item/RAND_MAX" href="https://baike.baidu.com/item/RAND_MAX">RAND_MAX</a><span style="color:#333333">和MB_CUR_MAX等等; 常用的函数如malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等等。 具体的内容可以打开</span><a data-cke-saved-href="https://baike.baidu.com/item/%E7%BC%96%E8%AF%91%E5%99%A8" href="https://baike.baidu.com/item/%E7%BC%96%E8%AF%91%E5%99%A8">编译器</a><span style="color:#333333">的include目录里面的stdlib.h头文件查看。</span>
</span>
传统 C++ 
#include <assert.h>    //设定插入点 
#include <ctype.h>     //字符处理 
#include <errno.h>     //定义错误码 
#include <float.h>     //浮点数处理 
#include <fstream.h>    //文件输入/输出 
#include <iomanip.h>    //参数化输入/输出 
#include <iostream.h>   //数据流输入/输出 
#include <limits.h>    //定义各种数据类型最值常量 
#include <locale.h>    //定义本地化函数 
#include <math.h>     //定义数学函数 
#include <stdio.h>     //定义输入/输出函数 
#include <stdlib.h>    //定义杂项函数及内存分配函数 
#include <string.h>    //字符串处理 
#include <strstrea.h>   //基于数组的输入/输出 
#include <time.h>     //定义关于时间的函数 
#include <wchar.h>     //宽字符处理及输入/输出 
#include <wctype.h>    //宽字符分类 

// 

标准 C++ (同上的不再注释) 

#include <algorithm>    //STL 通用算法 
#include <bitset>     //STL 位集容器 
#include <cctype> 
#include <cerrno> 
#include <clocale> 
#include <cmath> 
#include <complex>     //复数类 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <ctime> 
#include <deque>      //STL 双端队列容器 
#include <exception>    //异常处理类 
#include <fstream> 
#include <functional>   //STL 定义运算函数(代替运算符) 
#include <limits> 
#include <list>      //STL 线性列表容器 
#include <map>       //STL 映射容器 
#include <iomanip> 
#include <ios>       //基本输入/输出支持 
#include <iosfwd>     //输入/输出系统使用的前置声明 
#include <iostream> 
#include <istream>     //基本输入流 
#include <ostream>     //基本输出流 
#include <queue>      //STL 队列容器 
#include <set>       //STL 集合容器 
#include <sstream>     //基于字符串的流 
#include <stack>      //STL 堆栈容器     
#include <stdexcept>    //标准异常类 
#include <streambuf>    //底层输入/输出支持 
#include <string>     //字符串类 
#include <utility>     //STL 通用模板类 
#include <vector>     //STL 动态数组容器 
#include <cwchar> 
#include <cwctype> 

using namespace std; 

// 

C99 增加 

#include <complex.h>   //复数处理 
#include <fenv.h>    //浮点环境 
#include <inttypes.h>  //整数格式转换 
#include <stdbool.h>   //布尔环境 
#include <stdint.h>   //整型环境 
#include <tgmath.h>   //通用类型数学宏
#include <assert.h>    //设定插入点 
#include <ctype.h>     //字符处理 
#include <errno.h>     //定义错误码 
#include <float.h>     //浮点数处理 
#include <fstream.h>    //文件输入/输出 
#include <iomanip.h>    //参数化输入/输出 
#include <iostream.h>   //数据流输入/输出 
#include <limits.h>    //定义各种数据类型最值常量 
#include <locale.h>    //定义本地化函数 
#include <math.h>     //定义数学函数 
#include <stdio.h>     //定义输入/输出函数 
#include <stdlib.h>    //定义杂项函数及内存分配函数 
#include <string.h>    //字符串处理 
#include <strstrea.h>   //基于数组的输入/输出 
#include <time.h>     //定义关于时间的函数 
#include <wchar.h>     //宽字符处理及输入/输出 
#include <wctype.h>    //宽字符分类 

// 

标准 C++ (同上的不再注释) 

#include <algorithm>    //STL 通用算法 
#include <bitset>     //STL 位集容器 
#include <cctype> 
#include <cerrno> 
#include <clocale> 
#include <cmath> 
#include <complex>     //复数类 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <ctime> 
#include <deque>      //STL 双端队列容器 
#include <exception>    //异常处理类 
#include <fstream> 
#include <functional>   //STL 定义运算函数(代替运算符) 
#include <limits> 
#include <list>      //STL 线性列表容器 
#include <map>       //STL 映射容器 
#include <iomanip> 
#include <ios>       //基本输入/输出支持 
#include <iosfwd>     //输入/输出系统使用的前置声明 
#include <iostream> 
#include <istream>     //基本输入流 
#include <ostream>     //基本输出流 
#include <queue>      //STL 队列容器 
#include <set>       //STL 集合容器 
#include <sstream>     //基于字符串的流 
#include <stack>      //STL 堆栈容器     
#include <stdexcept>    //标准异常类 
#include <streambuf>    //底层输入/输出支持 
#include <string>     //字符串类 
#include <utility>     //STL 通用模板类 
#include <vector>     //STL 动态数组容器 
#include <cwchar> 
#include <cwctype> 

using namespace std; 

// 

C99 增加 

#include <complex.h>   //复数处理 
#include <fenv.h>    //浮点环境 
#include <inttypes.h>  //整数格式转换 
#include <stdbool.h>   //布尔环境 
#include <stdint.h>   //整型环境 
#include <tgmath.h>   //通用类型数学宏

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <assert h>     设定插入点 #include <ctype h>     字符处理 #include <errno h>     定义错误码 #include <float h>     浮点数处理 #include <fstream h>    文件输入/输出 #include <iomanip h>    参数化输入/输出 #include <iostream h>    数据流输入/输出 #include <limits h>     定义各种数据类型最值常量 #include <locale h>     定义本地化函数 #include <math h>      定义数学函数 #include <stdio h>     定义输入/输出函数 #include <stdlib h>     定义杂项函数及内存分配函数 #include <string h>     字符串处理 #include <strstrea h>    基于数组的输入/输出 #include <time h>      定义关于时间的函数 #include <wchar h>     宽字符处理及输入/输出 #include <wctype h>     宽字符分类 int spawnvpe int mode char pathname char argv[] char envp[] spawn函数族在mode模式下运行子程序pathname 并将参数 arg0 arg1 arg2 argv[] envp[] 传递给子程序 出错返回 1 mode为运行模式 mode为 P WAIT 表示在子程序运行完后返回本程序 P NOWAIT 表示在子程序运行时同时运行本程序 不可用 P OVERLAY表示在本程序退出后运行子程序 在spawn函数族中 后缀l v p e添加到spawn后 所指定的函数将具有某种操作能力 有后缀 p时 函数利用DOS的PATH查找子程序文件 l时 函数传递的参数个数固定 v时 函数传递的参数个数不固定 ">#include <assert h>     设定插入点 #include <ctype h>     字符处理 #include <errno h>     定义错误码 #include <float h>     浮点数处理 #include <fstream h>    文件输入/输出 #include <iomanip h& [更多]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值