c/c++ 头文件梳理

来源:互联网 发布:java社区 编辑:程序博客网 时间:2024/05/18 04:51

一:前言

进行linux下C\/C++ 服务端后台开发都知道,编程时刻需要跟各种头文件打交道。
比如使用printf函数则需要引用#include <stdio.h>,使用STL的map容器则要#include <map>,使用socket网络编程则要#include <sys/socket.h>
现在,我考你一个:uint32_t是在哪个头文件定义?sleep函数又是在哪个头文件?openclose是在同一个头文件里吗?
是不是有点一时半会答不上来,感觉头文件有成千上百数不胜数,永远也理不清到底有多少头文件,有没有好的方法能梳理头文件呢,如果能将头文件分门别类理清楚就更好了?
答案是可以的。

二:头文件分类

我把头文件分为以下三类:
- C标准头文件:一共29个头文件。

http://en.cppreference.com/w/c/header
- C++标准头文件:除C标准库外,还包括STL标准库等10+个头文件
http://www.cplusplus.com/reference/stl/
把C标准头文件放到std的命名空间里,文件名统一加上c前缀,如#include

三:(1)C标准库

- #include <string.h> 字符串操作相关    - memcpy /strcpy 区别?    - memset    - strncpy- #include <stdio.h> 标准输入输出    - fopen/fwrite    - printf/scanf- #include <stdio.h> 标准输入输出    - fopen/fwrite    - printf/scanf- #include <stdlib.h> 常用的一些函数库    - strtol/atoi    - malloc/free    - rand    - qsort    - abs/div    - size_t- #include <math.h> 函数库    - sin/cos    - pow/sqrt    - ceil/floor- #include <stdint.h>     - uint32_t    - SIZE_MAX- #include <ctype.h>    - islower    - toupper- #include <time.h>     - time    - mktime- #include <setjmp.h>...

三:(2)C++标准库


  • container类:

include

  • #include
    • share_ptr
  • #include
    • min/max
    • merge
    • lower_bound/upper_bound
    • sort
    • unique
    • remove
    • copy
    • find
  • 三:(3)linux系统

    - #include <unistd.h>    - chown()    - close()/write()/read()    - fsync()    - sleep()/usleep()    - getpid()- #include <fcntl.h>    - open()    - create()    - fcntl()- #include <pthread.h>- #include <fcntl.h>    - open()    - create()    - fcntl()- #include <pthread.h>- sys目录下    - <sys/shm.h>    - <sys/msg.h>    - <sys/socket.h>    - <sys/sem.h>    - <sys/stat.h>    - <sys/time.h>    - <sys/select.h>     - <sys/epoll.h>    - <sys/types.h>

    四:结语

    梳理完后一目了然,清晰很多,建议平时多进入头文件看看,对头文件多熟悉熟悉,写起代码来也能胸有成竹。

    0 0
    原创粉丝点击