EDA365电子论坛网
标题:
在Linux中C/C++的一些常用头文件的作用
[打印本页]
作者:
mytomorrow
时间:
2019-7-31 10:02
标题:
在Linux中C/C++的一些常用头文件的作用
( e8 H# q$ S1 x! a) `8 [
8 [* i9 \3 a) |, @5 l# F( [
<assert.h>:ANSI C。提供断言,assert(表达式)
1 v& D: D* o. ?4 |5 C
<glib.h>:GCC。GTK,GNOME的基础库,提供很多有用的函数,如有数据结构操作函数。使用glib只需要包含<glib.h>
# a' H" d$ c3 Z1 g
<dirent.h>:GCC。文件夹操作函数。struct dirent,struct DIR,opendir(),closedir(),readdir(),readdir64()等
: D4 m/ T: c! b
<ctype.h>:ANSI C。字符测试函数。isdigit(),islower()等
1 i4 v0 J$ L4 a( p1 C4 k5 L& b
<errno.h>:ANSI C。查看错误代码errno是调试程序的一个重要方法。当linuc C api函数发生异常时,一般会将errno变量(需include errno.h)赋一个整数值,不同的值表示不同的含义,可以通过查看该值推测出错的原因。在实际编程中用这一招解决了不少原本看来莫名其妙的问题。比较 麻烦的是每次都要去linux源代码里面查找错误代码的含义,现在把它贴出来,以后需要查时就来这里看了。来自linux 2.4.20-18的内核代码中的/usr/include/asm/errno.h
l, t: [# P0 C% M6 n' \
<getopt.h>:处理命令行参数。getopt()
1 B, ?" l9 B7 F. \
3 y7 Y" h! y5 a- i' c7 n
-------------------------
8 f- ^6 o! r1 J w% n- l6 d
0 J9 ] u& |) L
- @- k' o8 k7 d
linux常用头文件如下:
2 J1 f$ h" m* m% I" q& R
3 O& |: I7 m* u9 k8 v+ U d
9 [. R" L5 c m; v5 t8 T/ B% ~
POSIX标准定义的头文件
: P, n6 N3 P+ A! v* R5 G* K
% v4 n3 ?, K5 O* u& U a
0 A& \* R' B, T7 j( Y& h+ n
<dirent.h> 目录项
: s: h+ V2 j: a/ m3 Z- t6 H7 o; h
<fcntl.h> 文件控制
% u q' {1 c9 ^2 m( @* R# [( O1 a% |
<fnmatch.h> 文件名匹配类型
& Q( `& T: e5 q8 D& i
<glob.h> 路径名模式匹配类型
: i; c Z$ t3 D$ t! l' R
<grp.h> 组文件
7 `3 ]' Y) d, b ]7 \
<netdb.h> 网络数据库操作
( z" R5 x. @' l' e8 L r" r
<pwd.h> 口令文件
G- G- p* P/ Z0 w
<regex.h> 正则表达式
, F6 O# f. S* ]8 H5 [8 H: d
<tar.h> TAR归档值
- N- d1 c2 J7 x: v
<termios.h> 终端I/O
; H) s) R2 Y. j. _: a" G# v; J8 Y7 _
<unistd.h> 符号常量
! y+ p$ U N) g; @+ u; H) B. a
<utime.h> 文件时间
3 o5 o% D% x' n
<wordexp.h> 字符扩展类型
3 F; {0 g, z7 J: N+ p
' j4 ?" h+ ^8 g- Q% j
* i8 D3 M2 p2 C
-------------------------
& P2 r" {# `0 }, l* m
$ u. B" [7 ~9 D1 R N/ m
) n. E$ F1 ?. z0 q4 z* d4 X
<arpa/inet.h> INTERNET定义
: g6 G' }6 K# C5 K
<net/if.h> 套接字本地接口
{/ _; B- X5 R: l4 s
<netinet/in.h> INTERNET地址族
- c& o0 N6 z) b: @
<netinet/tcp.h> 传输控制协议定义
9 m, a( ?; w/ u1 U5 n3 d
9 w6 k6 |7 g- w% c: v/ W2 ?
+ W: f; F- y( a( F2 m# c6 i5 t
-------------------------
3 [8 U l/ F9 W' N, a
" ~9 n8 K! g1 K5 R; f& V
" d) J: E+ r: @% q) T- Y9 r
<sys/mman.h> 内存管理声明
) I1 [1 {3 k0 M d
<sys/select.h> Select函数
0 b, V( u2 p# B" |2 O) R4 d: a* A
<sys/socket.h> 套接字借口
0 n5 _, q' j' R9 U
<sys/stat.h> 文件状态
5 N9 `- s! ^$ Z6 B
<sys/times.h> 进程时间
6 s; R0 \7 e' { a3 `+ ]
<sys/types.h> 基本系统数据类型
5 @' T" t* B! d0 N8 x; }" d
<sys/un.h> UNIX域套接字定义
# j* o# x3 Y) h$ ^" k) L/ e
<sys/utsname.h> 系统名
( h1 K8 r% H$ S! {: h6 Q( K
<sys/wait.h> 进程控制
], @1 F$ p; Q" @6 v$ t6 c( T8 G
, E$ V, r& K# ~+ ~/ O; l& p9 C6 d- s
" `6 C+ x [& Y) u+ N8 }, a
------------------------------
: Y. g* G5 d4 {) H' P
. W2 M- ~0 E+ I( l
& [* H7 q& p4 z K& Y
POSIX定义的XSI扩展头文件
: l% C+ d2 O9 {4 [9 {1 U
3 w' @3 T" Z' Y' N. C
# u- K5 Q; w" p
<cpio.h> cpio归档值
! K% S8 @7 o" F6 j9 k4 M0 B
<dlfcn.h> 动态链接
X- K) ^: n# T3 }. d0 b7 x' B
<fmtmsg.h> 消息显示结构
0 |+ A3 P8 N/ T! c" g
<ftw.h> 文件树漫游
/ E6 b/ a7 A# e1 B) ~
<iconv.h> 代码集转换使用程序
# Z) M) p. S! B1 x) {8 c9 a
<langinfo.h> 语言信息常量
8 p0 a% n6 H4 q# J' C" E" @: {# b
<libgen.h> 模式匹配函数定义
, k7 M* _; q/ z" `1 z0 q* A
<monetary.h> 货币类型
- A7 J: H1 }: ^( u& m" z
<ndbm.h> 数据库操作
/ m0 V7 |+ N, n# P
<nl_types.h> 消息类别
1 p4 j# }, [8 `* x# D# x
<poll.h> 轮询函数
" I6 X. k* l9 a: _ y0 I8 r6 R
<search.h> 搜索表
! [ b b7 E) y: C4 A
<strings.h> 字符串操作
9 m# i) M. G6 C# ^
<syslog.h> 系统出错日志记录
; m5 ?2 F$ i1 D
<ucontext.h> 用户上下文
0 y' t6 g; d6 A1 m8 f( a# G& Z; }
<ulimit.h> 用户限制
4 X1 K1 D5 W- Y9 x) r
<utmpx.h> 用户帐户数据库
: a) ^/ s8 g5 G7 G+ ?
* E: K) d+ I0 @6 ^' E7 y" Y
# J" A9 O2 l# o4 M$ E
-----------------------------
/ s2 Y/ q$ n2 v, W- S: E& U$ \
8 U( t) g* r5 r9 Z/ F+ f
- y4 }/ ^; ~: c
<sys/ipc.h> IPC(命名管道)
/ F f" e" {( |' n
<sys/msg.h> 消息队列
1 W$ S( M/ b# v* z: Z( n
<sys/resource.h>资源操作
; m E+ a( j2 U* e& I+ n! m
<sys/sem.h> 信号量
8 a. |! M0 }: }. I9 G" x& k7 H
<sys/shm.h> 共享存储
4 d4 A+ |9 _7 y
<sys/statvfs.h> 文件系统信息
" F9 r2 ?2 n3 m! x
<sys/time.h> 时间类型
! d, Y# x- T9 \- q
<sys/timeb.h> 附加的日期和时间定义
1 E( {3 j$ K1 X/ t: B% j) x9 Y
<sys/uio.h> 矢量I/O操作
( ]. c( l# Y H! F: _+ J
& s% o+ z7 m( m- N* V1 e
6 R5 J8 C) c$ T. w
------------------------------
6 Y; Q. \! Y6 E: f
5 P8 F( ~$ o( R
4 y3 ` E2 r9 w$ A+ ?% m6 m
POSIX定义的可选头文件
/ E8 B3 ^, k7 f' u1 F3 C# ^7 Y
6 X4 {4 U: y, d8 T6 ?, L
. w2 \: z }. b' M
<aio.h> 异步I/O
, j' f% y0 y5 Y) f: c- B$ J
<mqueue.h> 消息队列
' L! Q- s& F N7 u
<pthread.h> 线程
+ I/ J6 [2 j& c& c
<sched.h> 执行调度
& _. X, p% C ]" }4 d) @5 A4 Q9 A
<semaphore.h> 信号量
0 U9 n0 |8 t8 }9 X
<spawn.h> 实时spawn接口
7 W, T7 o! n# B' T, Q
<stropts.h> XSI STREAMS接口
1 H0 z6 @7 p" _6 F L
<trace.h> 事件跟踪
8 A$ G" M( c% ?* c; v
9 {& X. d' q8 L
9 d2 E3 I/ g3 T7 C0 C+ @! F
3、 C/C++头文件一览
/ d9 R1 d' S; T, Q2 I
2 C F) J3 \- N# g7 l9 b$ M5 p" M
% E% h' t7 C' d5 {
C
1 _3 V C( n; d
4 w1 r- M) R- S- G$ Z3 g
7 o& L7 v# M _
#include <assert.h> //设定插入点
; e3 W! B) D1 O4 v( b
#include <ctype.h> //字符处理
: Z# x+ V, I( ]2 l/ \* |" c: {/ a
#include <errno.h> //定义错误码
+ b T" y* e, m* T3 h
#include <float.h> //浮点数处理
2 K8 D4 X1 b+ ]$ q% Z' }0 M! s' p/ p
#include <iso646.h> //对应各种运算符的宏
3 a5 V+ W' y7 U+ ?
#include <limits.h> //定义各种数据类型最值的常量
" Y5 D1 p3 j+ C3 O4 u
#include <locale.h> //定义本地化C函数
' s$ D7 t' A1 X1 V3 Z8 Q) _
#include <math.h> //定义数学函数
7 I" j) D4 n, ~4 C
#include <setjmp.h> //异常处理支持
# M& @0 r+ V5 A4 T [
#include <signal.h> //信号机制支持
. C7 f( Z, k- o! }
#include <stdarg.h> //不定参数列表支持
6 o. {5 ^( U( p) O# s
#include <stddef.h> //常用常量
8 m4 Q4 s+ s8 H" b
#include <stdio.h> //定义输入/输出函数
! r% t5 s5 \* T# q h# d5 W
#include <stdlib.h> //定义杂项函数及内存分配函数
" b. _- ?( {: w8 H4 x
#include <string.h> //字符串处理
% g: c, V4 i0 h; I
#include <time.h> //定义关于时间的函数
' ]2 j+ N! n! L" B
#include <wchar.h> //宽字符处理及输入/输出
" S$ L. b! i. m) x8 S- B& i
#include <wctype.h> //宽字符分类
. l. b" S/ M: w1 z+ p2 F# w
1 I% V, T z: S% P9 \
- m0 d! P% o+ Z3 F6 Y5 e3 u2 @
传统C++
5 G) {* E9 ?! A8 r) O
6 N1 v, R) v+ w% Z
, N& \7 F9 _! {" Z( [
#include <fstream.h> //改用<fstream>
2 u9 u3 }# L A
#include <iomanip.h> //改用<iomainip>
# `; R+ C4 i" n" Z+ _2 P4 o {
#include <iostream.h> //改用<iostream>
5 M" ?! H) ]9 X, i
#include <strstrea.h> //该类不再支持,改用<sstream>中的stringstream
: Z |" K* V6 _# U: I8 _
( {7 f a8 v+ @& X; ~& B' T' m
( [. _6 Y! i7 ]* ~* N& O0 W
————————————————————————————————
1 m, \' _8 m$ e$ j- ?) S
0 E* X$ \$ @. i
2 j. X$ G7 d# I# i' i; p' S
标准C++
. x) |: N( ]" z# p/ f
3 s; A% b4 Z8 H5 t
0 p+ d) o! D# n
#include <algorithm> //STL 通用算法
/ s3 r* A9 D+ N
#include <bitset> //STL 位集容器
P( \ [9 A7 i0 u
#include <cctype> //字符处理
* f; s+ R) I2 \3 S
#include <cerrno> //定义错误码
$ F7 J6 L7 j7 f l0 R' r
#include <cfloat> //浮点数处理
4 L" p# ~+ b5 d6 x$ @" v6 o4 g; J
#include <ciso646> //对应各种运算符的宏
6 A8 D$ _; s1 t; p) ^# U" l
#include <climits> //定义各种数据类型最值的常量
2 x, ^5 x7 ~3 ?3 D- V# [: ^
#include <clocale> //定义本地化函数
4 D9 I1 f* z+ E6 \; [. v0 g, M$ K
#include <cmath> //定义数学函数
& p2 J6 O' W! y( d3 e+ n* ?
#include <complex> //复数类
4 d& W5 X5 c) M: V+ V; t
#include <csignal> //信号机制支持
' p5 N& o0 m* E
#include <csetjmp> //异常处理支持
6 j2 V) X# U, T: X
#include <cstdarg> //不定参数列表支持
+ a" Q) }3 o& }* q
#include <cstddef> //常用常量
$ c1 o. I- c" H/ U/ x
#include <cstdio> //定义输入/输出函数
! R2 P5 j0 a( E* l
#include <cstdlib> //定义杂项函数及内存分配函数
" h7 E0 `2 [/ H W* k; `5 V+ S
#include <cstring> //字符串处理
# }' e$ x; o7 m
#include <ctime> //定义关于时间的函数
8 W# L+ w- q: K2 o ?3 N% N& @
#include <cwchar> //宽字符处理及输入/输出
) o0 p* Q) P! a7 P/ Z
#include <cwctype> //宽字符分类
, d, v; X8 l0 o, h3 _
#include <deque> //STL 双端队列容器
! P( Y G6 P, A6 H/ D
#include <exception> //异常处理类
! h9 s, ~' e0 V7 R! S5 T: Q8 ^
#include <fstream> //文件输入/输出
2 c3 |' Q: K" q* P7 c: r5 I
#include <functional> //STL 定义运算函数(代替运算符)
& n5 E5 ~2 B- W* p/ z
#include <limits> //定义各种数据类型最值常量
: p9 C' |6 F L
#include <list> //STL 线性列表容器
# P+ u" g% L' u* t1 U
#include <locale> //本地化特定信息
' \: r+ x# q! U$ C6 l6 N9 [+ T3 w
#include <map> //STL 映射容器
& F( x/ X6 a2 c* h( Z
#include <memory> //STL通过分配器进行的内存分配
, E+ ^# E* ^$ K; o' ?5 ^
#include <new> //动态内存分配
& z4 U4 \; H1 x, ^# s Z- |% P/ S# q; ]
#include <numeric> //STL常用的数字操作
" q; x5 Y! z0 {6 s3 X5 L
#include <iomanip> //参数化输入/输出
) \5 `1 j: y& N9 s( L9 }
#include <ios> //基本输入/输出支持
+ _% z4 `9 W. \) [& j0 `
#include <iosfwd> //输入/输出系统使用的前置声明
; f9 N( D- l( d' S; |, r& i
#include <iostream> //数据流输入/输出
' N3 Y' t) c S1 Y4 K, K- ~9 d7 i h& B- h1 {
#include <istream> //基本输入流
2 m# V6 W; K/ Y$ A4 j2 f9 V
#include <iterator> //STL迭代器
' S( F- T5 z9 O" b8 w! ~5 y8 \
#include <ostream> //基本输出流
3 x D; i) S/ m. c9 H( t2 Z
#include <queue> //STL 队列容器
' p% f6 Z, |1 I# r
#include <set> //STL 集合容器
& ]# o% Z4 Z' a5 u
#include <sstream> //基于字符串的流
) @, _- J7 I1 Q! s0 n+ G4 d3 |
#include <stack> //STL 堆栈容器
9 ^3 X( n8 {0 G# p8 u7 | A
#include <stdexcept> //标准异常类
+ d# V% K9 v g5 x* y f5 ?/ r
#include <streambuf> //底层输入/输出支持
- p& C y1 I( D, B) `! b; x
#include <string> //字符串类
$ j, B7 R7 j3 {9 f. p7 y' H9 _
#include <typeinfo> //运行期间类型信息
* i, x: Z6 `3 d; U& Q
#include <utility> //STL 通用模板类
$ S, f1 }+ V8 q! |5 F
#include <valarray> //对包含值的数组的操作
4 r$ T f+ M I, m, P
#include <vector> //STL 动态数组容器
8 M( T: u) a3 G" z) E
+ f- I7 q/ p% ~# W/ Y
+ b" P. `1 r- C, ~5 b2 I2 m
0 ^' @8 g2 S/ R
" {7 \) `5 G( i: P& Q; J* @. ]! _
& T6 \( `. D/ p- S# e. p5 d
- a4 B. N5 A$ f, p" W. A% y" ^
) k; N8 b" J* w7 w4 ]% z9 p6 x
6 Z( y: H( D+ S2 ?9 k
作者:
fanichicl
时间:
2019-7-31 18:18
看看在Linux中C/C++的一些常用头文件的作用
欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/)
Powered by Discuz! X3.2