一:前言
進行linux下C/C++服務端后台開發的都知道,需要跟各種頭文件打交道。
比如使用printf函數則需要引用#include <stdio.h>,使用STL的map容器則要#include <map>,使用socket網絡編程則要#include <sys/socket.h>,
那么我考考你uint32_t是在哪個頭文件定義的呢?sleep函數又是在哪個頭文件?open和close是在同一個頭文件里嗎?
是不是有點一時半會答不上來,有沒有好的方法能梳理頭文件呢,把頭文件進行分門別類呢?
答案是可以的。
我把頭文件分為以下三類:
- C標准頭文件:一共29個頭文件。 http://en.cppreference.com/w/c/header點擊打開鏈接
- C++標准頭文件:除C標准庫外,還包括STL標准庫等10+個頭文件 http://www.cplusplus.com/reference/stl/ 。把C標准頭文件放到std的命名空間里,文件名統一加上c前綴,如#include <string.h> 改成#include <cstring>外,
- linux系統頭文件:操作系統相關,如socket網絡、共享內存、信號量等,常用的就10+左右。http://pubs.opengroup.org/onlinepubs/7908799/headix.html
二:C標准庫
- #include <string.h> 字符串操作相關
memcpy /strcpy 區別?memsetstrncpy
- #include <stdio.h> 標准輸入輸出
fopen/fwriteprintf/scanf
- #include <stdio.h> 標准輸入輸出
fopen/fwriteprintf/scanf
- #include <stdlib.h> 常用的一些函數庫
strtol/atoimalloc/freerandqsortabs/divsize_t
- #include <math.h> 函數庫
sin/cospow/sqrtceil/floor
- #include <stdint.h>
uint32_tSIZE_MAX
- #include <ctype.h>
islowertoupper
- #include <time.h>
timemktime
- #include <setjmp.h>...
三、C++標准庫
- #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>
五、結語
這樣是不是一目了然,清晰很多。