C/C++ 库函数

C、传统 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>   //通用类型数学宏

C头文件大全

 

分类函数,所在函数库为ctype.h

int isalpha(int ch)  若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0

int isalnum(int ch)  若ch是字母('A'-'Z','a'-'z')或数字('0'-'9')

                     返回非0值,否则返回0

int isascii(int ch)  若ch是字符(ASCII码中的0-127)返回非0值,否则返回0

int iscntrl(int ch)  若ch是作废字符(0x7F)或普通控制字符(0x00-0x1F)

                     返回非0值,否则返回0

int isdigit(int ch)  若ch是数字('0'-'9')返回非0值,否则返回0

int isgraph(int ch)  若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0

int islower(int ch)  若ch是小写字母('a'-'z')返回非0值,否则返回0

int isprint(int ch)  若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0

int ispunct(int ch)  若ch是标点字符(0x00-0x1F)返回非0值,否则返回0

int isspace(int ch)  若ch是空格(' '),水平制表符('/t'),回车符('/r'),

                     走纸换行('/f'),垂直制表符('/v'),换行符('/n')

                     返回非0值,否则返回0

int isupper(int ch)  若ch是大写字母('A'-'Z')返回非0值,否则返回0

int isxdigit(int ch) 若ch是16进制数('0'-'9','A'-'F','a'-'f')返回非0值,

                     否则返回0

int tolower(int ch)  若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')

int toupper(int ch)  若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')

 

数学函数,所在函数库为math.h、stdlib.h、string.h、float.h

int      abs(int i)                    返回整型参数i的绝对值

double  cabs(struct complex znum)      返回复数znum的绝对值

double  fabs(double x)                 返回双精度参数x的绝对值

long    labs(long n)                   返回长整型参数n的绝对值

double   exp(double x)                 返回指数函数ex的值

double frexp(double value,int *eptr)   返回value=x*2n中x的值,n存贮在eptr中

double ldexp(double value,int exp);    返回value*2exp的值

double   log(double x)                 返回logex的值

double log10(double x)                 返回log10x的值

double   pow(double x,double y)        返回xy的值

double pow10(int p)                    返回10p的值

double  sqrt(double x)                 返回+√x的值

double  acos(double x)                 返回x的反余弦cos-1(x)值,x为弧度

double  asin(double x)                 返回x的反正弦sin-1(x)值,x为弧度

double  atan(double x)                 返回x的反正切tan-1(x)值,x为弧度

double atan2(double y,double x)        返回y/x的反正切tan-1(x)值,y的x为弧度

double   cos(double x)                 返回x的余弦cos(x)值,x为弧度

double   sin(double x)                 返回x的正弦sin(x)值,x为弧度

double   tan(double x)                 返回x的正切tan(x)值,x为弧度

double  cosh(double x)                 返回x的双曲余弦cosh(x)值,x为弧度

double  sinh(double x)                 返回x的双曲正弦sinh(x)值,x为弧度

double  tanh(double x)                 返回x的双曲正切tanh(x)值,x为弧度

double hypot(double x,double y)        返回直角三角形斜边的长度(z),

                                       x和y为直角边的长度,z2=x2+y2

double  ceil(double x)                 返回不小于x的最小整数

double floor(double x)                 返回不大于x的最大整数

void   srand(unsigned seed)            初始化随机数发生器

int     rand()                         产生一个随机数并返回这个数

double  poly(double x,int n,double c[])从参数产生一个多项式

double  modf(double value,double *iptr)将双精度数value分解成尾数和阶

double  fmod(double x,double y)        返回x/y的余数

double frexp(double value,int *eptr)   将双精度数value分成尾数和阶

double  atof(char *nptr)               将字符串nptr转换成浮点数并返回这个浮点数

double  atoi(char *nptr)               将字符串nptr转换成整数并返回这个整数

double  atol(char *nptr)               将字符串nptr转换成长整数并返回这个整数

char   *ecvt(double value,int ndigit,int *decpt,int *sign)

         将浮点数value转换成字符串并返回该字符串

char   *fcvt(double value,int ndigit,int *decpt,int *sign)

         将浮点数value转换成字符串并返回该字符串

char   *gcvt(double value,int ndigit,char *buf)

         将数value转换成字符串并存于buf中,并返回buf的指针

char  *ultoa(unsigned long value,char *string,int radix)

         将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char   *ltoa(long value,char *string,int radix)

         将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char   *itoa(int value,char *string,int radix)

         将整数value转换成字符串存入string,radix为转换时所用基数

double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0

int    atoi(char *nptr) 将字符串nptr转换成整型数,  并返回这个数,错误返回0

long   atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0

double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数,

long   strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,

                                               并返回这个数,

int          matherr(struct exception *e)

              用户修改数学错误返回信息函数(没有必要使用)

double       _matherr(_mexcep why,char *fun,double *arg1p,

                      double *arg2p,double retval)

                用户修改数学错误返回信息函数(没有必要使用)

unsigned int _clear87()   清除浮点状态字并返回原来的浮点状态

void         _fpreset()   重新初使化浮点数学程序包

unsigned int _status87()  返回浮点状态字

 

目录函数,所在函数库为dir.h、dos.h

int     chdir(char *path) 使指定的目录path(如:"C://WPS")变成当前的工作目录,成

         功返回0

int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的文件,成功

     返回0

     pathname为指定的目录名和文件名,如"C://WPS//TXT"

     ffblk为指定的保存文件信息的一个结构,定义如下:

    ┏━━━━━━━━━━━━━━━━━━┓

    ┃struct ffblk                        ┃

    ┃{                                   ┃

    ┃ char ff_reserved[21]; /*DOS保留字*/┃

    ┃ char ff_attrib;       /*文件属性*/ ┃

    ┃ int  ff_ftime;        /*文件时间*/ ┃

    ┃ int  ff_fdate;        /*文件日期*/ ┃

    ┃ long ff_fsize;        /*文件长度*/ ┃

    ┃ char ff_name[13];     /*文件名*/   ┃

    ┃}                                   ┃

    ┗━━━━━━━━━━━━━━━━━━┛

     attrib为文件属性,由以下字符代表

    ┏━━━━━━━━━┳━━━━━━━━┓

    ┃FA_RDONLY 只读文件┃FA_LABEL  卷标号┃

    ┃FA_HIDDEN 隐藏文件┃FA_DIREC  目录  ┃

    ┃FA_SYSTEM 系统文件┃FA_ARCH   档案  ┃

    ┗━━━━━━━━━┻━━━━━━━━┛

    例:

    struct ffblk ff;

    findfirst("*.wps",&ff,FA_RDONLY);

 

int   findnext(struct ffblk *ffblk)      取匹配finddirst的文件,成功返回0

void  fumerge(char *path,char *drive,char *dir,char *name,char *ext)

       此函数通过盘符drive(C:、A:等),路径dir(/TC、/BC/LIB等),

       文件名name(TC、WPS等),扩展名ext(.EXE、.COM等)组成一个文件名

       存与path中.

int   fnsplit(char *path,char *drive,char *dir,char *name,char *ext)

       此函数将文件名path分解成盘符drive(C:、A:等),路径dir(/TC、/BC/LIB等),

       文件名name(TC、WPS等),扩展名ext(.EXE、.COM等),并分别存入相应的变量中.

int   getcurdir(int drive,char *direc) 此函数返回指定驱动器的当前工作目录名称

        drive 指定的驱动器(0=当前,1=A,2=B,3=C等)

        direc 保存指定驱动器当前工作路径的变量      成功返回0

char *getcwd(char *buf,iint n) 此函数取当前工作目录并存入buf中,直到n个字

      节长为为止.错误返回NULL

int   getdisk() 取当前正在使用的驱动器,返回一个整数(0=A,1=B,2=C等)

int   setdisk(int drive) 设置要使用的驱动器drive(0=A,1=B,2=C等),

       返回可使用驱动器总数

int   mkdir(char *pathname)  建立一个新的目录pathname,成功返回0

int   rmdir(char *pathname)  删除一个目录pathname,成功返回0

char *mktemp(char *template) 构造一个当前目录上没有的文件名并存于template中

char *searchpath(char *pathname) 利用MSDOS找出文件filename所在路径,

      ,此函数使用DOS的PATH变量,未找到文件返回NULL

 

进程函数,所在函数库为stdlib.h、process.h

void  abort() 此函数通过调用具有出口代码3的_exit写一个终止信息于stderr,

        并异常终止程序。无返回值

int   exec…装入和运行其它程序

int   execl(  char *pathname,char *arg0,char *arg1,…,char *argn,NULL)

int   execle( char *pathname,char *arg0,char *arg1,…,

              char *argn,NULL,char *envp[])

int   execlp( char *pathname,char *arg0,char *arg1,…,NULL)

int   execlpe(char *pathname,char *arg0,char *arg1,…,NULL,char *envp[])

int   execv(  char *pathname,char *argv[])

int   execve( char *pathname,char *argv[],char *envp[])

int   execvp( char *pathname,char *argv[])

int   execvpe(char *pathname,char *argv[],char *envp[])

         exec函数族装入并运行程序pathname,并将参数

          arg0(arg1,arg2,argv[],envp[])传递给子程序,出错返回-1

       在exec函数族中,后缀l、v、p、e添加到exec后,

       所指定的函数将具有某种操作能力

      有后缀  p时,函数可以利用DOS的PATH变量查找子程序文件。

              l时,函数中被传递的参数个数固定。

              v时,函数中被传递的参数个数不固定。

              e时,函数传递指定参数envp,允许改变子进程的环境,

                   无后缀e时,子进程使用当前程序的环境。

 

void  _exit(int status)终止当前程序,但不清理现场

void  exit(int status) 终止当前程序,关闭所有文件,写缓冲区的输出(等待输出),

                       并调用任何寄存器的"出口函数",无返回值

 

int   spawn…运行子程序

int   spawnl(  int mode,char *pathname,char *arg0,char *arg1,…,

               char *argn,NULL)

int   spawnle( int mode,char *pathname,char *arg0,char *arg1,…,

               char *argn,NULL,char *envp[])

int   spawnlp( int mode,char *pathname,char *arg0,char *arg1,…,

               char *argn,NULL)

int   spawnlpe(int mode,char *pathname,char *arg0,char *arg1,…,

               char *argn,NULL,char *envp[])

int   spawnv(  int mode,char *pathname,char *argv[])

int   spawnve( int mode,char *pathname,char *argv[],char *envp[])

int   spawnvp( int mode,char *pathname,char *argv[])

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时, 函数传递的参数个数不固定.

               e时, 指定参数envp可以传递给子程序,允许改变子程序运行环境.

                  当无后缀e时,子程序使用本程序的环境.

 

int   system(char *command) 将MSDOS命令command传递给DOS执行

 

转换子程序,函数库为math.h、stdlib.h、ctype.h、float.h

char   *ecvt(double value,int ndigit,int *decpt,int *sign)

         将浮点数value转换成字符串并返回该字符串

char   *fcvt(double value,int ndigit,int *decpt,int *sign)

         将浮点数value转换成字符串并返回该字符串

char   *gcvt(double value,int ndigit,char *buf)

         将数value转换成字符串并存于buf中,并返回buf的指针

char  *ultoa(unsigned long value,char *string,int radix)

         将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char   *ltoa(long value,char *string,int radix)

         将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char   *itoa(int value,char *string,int radix)

         将整数value转换成字符串存入string,radix为转换时所用基数

double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0

int    atoi(char *nptr) 将字符串nptr转换成整型数,  并返回这个数,错误返回0

long   atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0

double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数,

long   strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,

                                               并返回这个数,

int    toascii(int c)   返回c相应的ASCII

int    tolower(int ch)  若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')

int   _tolower(int ch)  返回ch相应的小写字母('a'-'z')

int    toupper(int ch)  若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')

int   _toupper(int ch)  返回ch相应的大写字母('A'-'Z')

 

诊断函数,所在函数库为assert.h、math.h

void   assert(int test) 一个扩展成if语句那样的宏,如果test测试失败,

        就显示一个信息并异常终止程序,无返回值

void   perror(char *string) 本函数将显示最近一次的错误信息,格式如下:

        字符串string:错误信息

char   *strerror(char *str) 本函数返回最近一次的错误信息,格式如下:

        字符串str:错误信息

int    matherr(struct exception *e)

        用户修改数学错误返回信息函数(没有必要使用)

double _matherr(_mexcep why,char *fun,double *arg1p,

                double *arg2p,double retval)

        用户修改数学错误返回信息函数(没有必要使用)

 

输入输出子程序,函数库为io.h、conio.h、stat.h、dos.h、stdio.h、signal.h

int   kbhit()    本函数返回最近所敲的按键

int   fgetchar() 从控制台(键盘)读一个字符,显示在屏幕上

int   getch()    从控制台(键盘)读一个字符,不显示在屏幕上

int   putch()    向控制台(键盘)写一个字符

int   getchar()  从控制台(键盘)读一个字符,显示在屏幕上

int   putchar()  向控制台(键盘)写一个字符

int   getche()   从控制台(键盘)读一个字符,显示在屏幕上

int   ungetch(int c) 把字符c退回给控制台(键盘)

char *cgets(char *string) 从控制台(键盘)读入字符串存于string中

int   scanf(char *format[,argument…])从控制台读入一个字符串,分别对各个参数进行

       赋值,使用BIOS进行输出

int   vscanf(char *format,Valist param)从控制台读入一个字符串,分别对各个参数进行

       赋值,使用BIOS进行输出,参数从Valist param中取得

int   cscanf(char *format[,argument…])从控制台读入一个字符串,分别对各个参数进行

       赋值,直接对控制台作操作,比如显示器在显示时字符时即为直接写频方式显示

int   sscanf(char *string,char *format[,argument,…])通过字符串string,分别对各个

       参数进行赋值

int   vsscanf(char *string,char *format,Vlist param)通过字符串string,分别对各个

       参数进行赋值,参数从Vlist param中取得

int   puts(char *string)  发关一个字符串string给控制台(显示器),

       使用BIOS进行输出

void  cputs(char *string) 发送一个字符串string给控制台(显示器),

       直接对控制台作操作,比如显示器即为直接写频方式显示

int   printf(char *format[,argument,…]) 发送格式化字符串输出给控制台(显示器)

       使用BIOS进行输出

int   vprintf(char *format,Valist param) 发送格式化字符串输出给控制台(显示器)

       使用BIOS进行输出,参数从Valist param中取得

int   cprintf(char *format[,argument,…]) 发送格式化字符串输出给控制台(显示器),

       直接对控制台作操作,比如显示器即为直接写频方式显示

int   vcprintf(char *format,Valist param)发送格式化字符串输出给控制台(显示器),

       直接对控制台作操作,比如显示器即为直接写频方式显示,

       参数从Valist param中取得

int   sprintf(char *string,char *format[,argument,…])

        将字符串string的内容重新写为格式化后的字符串

int   vsprintf(char *string,char *format,Valist param)

        将字符串string的内容重新写为格式化后的字符串,参数从Valist param中取得

int   rename(char *oldname,char *newname)将文件oldname的名称改为newname

int   ioctl(int handle,int cmd[,int *argdx,int argcx])

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值