c++的头文件

本文介绍了C++标准库中的核心头文件,包括传统C++和标准C++中用于不同功能模块的头文件,如数学函数、输入输出、字符串处理等,并涵盖了C99新增的特性。
1、传统 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>     宽字符分类 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& [更多]
### C++ 头文件使用指南 C++ 头文件是编程语言中非常重要的组成部分,它们提供了标准库的功能支持,使得开发者能够更高效地编写代码。以下是关于 C++ 头文件的常见列表和使用方法: #### 1. 标准 C++ 头文件 C++ 吸收了 C 的大部分头文件,并对其进行了改进。这些头文件通常以 `c` 开头,并移除了 `.h` 扩展名[^1]。例如: - `<cmath>`:数学函数,如 `sqrt` 和 `sin`。 - `<cstring>`:字符串操作函数,如 `strcpy` 和 `strlen`。 - `<cstdio>`:输入输出函数,如 `printf` 和 `scanf`。 此外,C++ 还引入了自己的头文件,用于支持更高级的功能。以下是一些常见的 C++ 头文件及其用途[^2]: - `<iostream>`:输入输出流支持,包括 `cin` 和 `cout`。 - `<string>`:定义 `std::string` 类型。 - `<vector>`:动态数组支持。 - `<map>`:键值对容器支持。 - `<algorithm>`:算法支持,如排序和查找。 #### 2. 万能头文件 为了方便开发,有时可以使用万能头文件 `<bits/stdc++.h>`,它包含了几乎所有的标准库头文件[^3]。然而,这种方法会增加编译时间和可执行文件的大小,因此不推荐在生产环境中使用。 #### 3. 常见头文件及功能 以下是一些常用的 C++ 头文件及其功能[^4]: - `<assert.h>` 或 `<cassert>`:用于调试时的断言检查。 - `<ctype.h>` 或 `<cctype>`:字符处理函数,如 `isalpha` 和 `isdigit`。 - `<math.h>` 或 `<cmath>`:数学函数支持。 - `<string.h>` 或 `<cstring>`:字符串操作函数。 - `<time.h>` 或 `<ctime>`:时间相关函数。 - `<fstream>`:文件输入输出支持。 #### 示例代码 以下是一个简单的示例,展示了如何使用 `<iostream>` 和 `<string>` 头文件: ```cpp #include <iostream> #include <string> int main() { std::string name; std::cout << "请输入你的名字: "; std::cin >> name; std::cout << "你好, " << name << "!" << std::endl; return 0; } ``` #### 注意事项 - 使用头文件时,应尽量避免重复包含相同的头文件,可以通过 `#ifndef`、`#define` 和 `#endif` 宏来实现保护。 - 对于较大的项目,建议仅包含实际需要的头文件,以减少编译时间和可执行文件大小。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值