c++函數常用

來源:互聯網
上載者:User

標籤:獲得一個字元   bytes   關閉   abs   unix   cti   mic   檔案的時間   mcc   

isalnum 判斷一個字元是否是字元類的數字或字母
isalpha判斷一個字元是否是字母
isblank判斷一個字元是否是空白字元(空格,水平定位字元,TAB)
iscntrl判斷一個控制符(ASCII碼0-31之間的字元)
isdigit判斷一個字元是否是字元類的數字
isgraph判斷一個字元是否是可列印字元(ASCII碼33-126之間的字元)
islower判斷一個字元是否是小寫字母
isprint判斷一個字元是否是包含空格在內的可列印字元(ASCII碼33-126之間的字元)
ispunct判斷一個字元是否是除空格,字母,數字外的標點符號
isspace判斷一個字元是空白字元(空格,分行符號,走紙符,斷行符號符,垂直定位字元,水平定位字元)
isupper判斷一個字元是否是大寫字母
isxdigit判斷一個字元是否是一個十六進位的數字
tolower將大寫字元轉換成小寫
toupper將小寫字元轉換成大寫

size_t sizeof
NULLnull 指標
FILE檔案的類型
fpos_t檔案中的指標的位置
EOF檔案末尾<0
FILENAME_MAX檔案名稱最大值>0
FOPEN_MAX同時開啟檔案的最大值>8
SEEK_SET檔案頭
SEEK_CUR檔案當前位置
SEEK_END檔案末尾
FILE *fopen(const char *filename,const char * mode);開啟檔案
FILE *freopen(const char *filename,const char* mode,FILE *stream)更改當前流相關的檔案
int fclose(FILE *stream)關閉檔案
void clearerr(FILE *stream)清除流中的錯誤標誌或檔案末尾標誌
int feof(FILE *stream)測試流上的檔案末尾標誌
int ferror(FILE *stream)測試流上的錯誤標誌
int ungetc(int c,FILE *stream)將一個字元放回到流中
int fgetc(FILE *stream)從流中讀一個字元
int getc(FILE *stream)從流中讀一個字元
int fputc(int c, FILE *stream)寫一個字元到一個流
int putc(int c, FILE *stream)寫一個字元到一個流
char *fgets(char *s, int n, FILE *stream)從流中擷取一個字串
int fputs(const char *s, FILE *stream)寫一個字串到一個流
int fprintf(FILE *stream,const char *format, ...)列印一個格式化資料到一個流
int vfprintf(FILE *stream,const char *format, va_list ap)使用一個參量列表指標格式化到流的資料
int fscanf(FILE *stream, const char *format, ...)從一個流中讀取格式化資料
size_t fread(char *buffer,size_t size,size_t count,FILE *stream)從一個流中讀資料
int fwrite(const char *buffer,size_t size,size_t count,FILE *stream)寫資料到一個流
int fgetpos(FILE *stream, fpos_t *pos)擷取流的檔案位置指示符
int fsetpos(FILE *stream, const fpos_t *pos)設定流位置指示符
int fseek(FILE *stream, long offset, int origin)移動檔案指標到一個指定的位置
long ftell(FILE *stream)獲得檔案指標相對於檔案頭的位移量
void rewind(FILE *steam)重新置放一個檔案指標到檔案開頭
int remove(const char *path)刪除一個檔案
int rename(const char *oldname, const char *newname)更改一個檔案或目錄
_IOFBF滿緩衝:當緩衝區為空白時,從流讀入資料。或者當緩衝區滿時,向流寫入數 據
_IOLBF行緩衝:每次從流中讀入一行資料或向流中寫入一行資料
_IONBF無緩衝:直接從流中讀入資料或直接向流中寫入資料,而沒有緩衝區
BUFSIZE緩衝區尺寸>=256
int fflush(FILE *stream)重新整理一個流並清空與流相關的緩衝區的內容
void setbuf(FILE *stream, char *buffer)控制流程的緩衝區,已經被setvbuf代替
int setvbuf(FILE *stream, char *buffer, int mode, size_t size)控制流程的緩衝區類型和緩衝區大小
int sprintf(char *buffer, const char *format, ...)將一個格式化資料寫入一個字串
int sscanf(const char *buffer, const char *format, ...)從字串中讀格式化資料
int vsprintf(char *buffer, const char *format, va_list ap)從參量列表指標格式化到字串
L_tmpnam臨時檔案名稱長度>0
TMP_MAX產生唯一檔案名的最大數目>=25
FILE *tmpfile(void)以二進位讀寫的方式建立一個臨時檔案
char *tmpname(char *string)建立一個臨時檔案名稱
stdin標準輸入資料流
stdout標準輸出資料流
stderr標準錯誤輸出資料流
int getchar(void)從 stdin 獲得一個字元
int putchar(int c)把字元寫道 stdout
char *gets(char *buffer)從 stdin 中擷取一行
int puts(const char *string)寫一個字串到 stdout
void perror(const char *error)列印一個錯誤訊息到 stderr
int printf(const char *format, ...)列印格式化資料到 stdout
int scanf(const char *format, ...)從 stdin 讀格式化資料
int vprintf(const char *format, va_list ap)從參量列表指標格式化到 stdout

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)返回 x的y次方 的值
double pow10(int p)返回 10的p次方 的值
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)
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)使用者修改數學錯誤返回資訊函數(沒有必要使用)
unsigned int _clear87()清除浮點狀態字並返回原來的浮點狀態
void _fpreset()重新初使化浮點數學程式包
unsigned int _status87()返回浮點狀態字

int chdir(char *path)使指定的目錄 path(如:"C:\\WPS")變成當前的工作目錄,成功則返回0
int findfirst(char *pathname,struct ffblk *ffblk,int attrib)尋找指定的檔案,成功返回0
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

void abort()此函數通過調用具有出口代碼 3 的_exit 寫一個終止資訊於 stderr,並異常終止程式。無傳回值
int exec…裝入和運行其它程式exec 函數族
void _exit(int status)終止當前程式,但不清理現場
void exit(int status)終止當前程式,關閉所有檔案,寫緩衝區的輸出(等待輸出),並調用任何寄存器的"出口函數",無傳回值
int spawn…運行子程式spawn 函數族
int system(char *command)將 MSDOS 命令 command 傳遞給 DOS 執行

int _open(char *pathname,int access)為讀或寫開啟一個檔案,按後按 access 來確定是讀檔案還是寫檔案,access 值查表
int open(char *pathname,int access[,int permiss])為讀或寫開啟一個檔案,按後按 access 來確定是讀檔案還是寫檔案,access 值查表.permiss 為檔案屬性,
int creat(char *filename,int permiss)建立一個新檔案 filename,並設定讀寫性.
int _creat(char *filename,int attrib)建立一個新檔案 filename,並設定檔案屬性。 attrib 為檔案屬性,
int creatnew(char *filenamt,int attrib)建立一個新檔案 filename,並設定檔案屬性。 attrib 為檔案屬性
int creattemp(char *filenamt,int attrib)建立一個新檔案 filename,並設定檔案屬性。 attrib 為檔案屬性,
int read(int handle,void *buf,int nbyte)從檔案號為 handle 的檔案中讀 nbyte 個字元存入 buf 中
nt _read(int handle,void *buf,int nbyte)從檔案號為 handle 的檔案中讀 nbyte 個字元存入 buf 中,直接調用 MSDOS 進行操作
int write(int handle,void *buf,int nbyte)將 buf 中的 nbyte 個字元寫入檔案號為 handle 的檔案中
int _write(int handle,void *buf,int nbyte)將 buf 中的 nbyte 個字元寫入檔案號為 handle 的檔案中
int dup(int handle)複製一個檔案處理指標 handle,返回這個指標
int dup2(int handle,int newhandle)複製一個檔案處理指標 handle 到 newhandle
int eof(int *handle)檢查檔案是否結束,結束返回 1,否則返回 0
long filelength(int handle)返迴文件長度, handle 為檔案號
int setmode(int handle,unsigned mode)本函數用來設定檔案號為 handle 的檔案的開啟檔案
int getftime(int handle,struct ftime *ftime)讀取檔案號為 handle 的檔案的時間,並將檔案時間存於 ftime 結構中,成功返回 0
int setftime(int handle,struct ftime *ftime)重寫檔案號為 handle 的檔案時間,新時間在結構 ftime 中.成功返回 0.
long lseek(int handle,long offset,int fromwhere)本函數將檔案號為 handle 的檔案的指標移到 fromwhere 後的第 offset 個位元組處
long tell(int handle)本函數返迴文件號為 handle 的檔案指標,以位元組表示
int isatty(int handle)本函數用來取裝置 handle 的類型
int lock(int handle,long offset,long length)對檔案分享權限設定作封鎖
int unlock(int handle,long offset,long length)開啟對檔案分享權限設定的封鎖
int close(int handle)關閉 handle 所表示的檔案處理
int _close(int handle)關閉 handle 所表示的檔案處理

mem…操作存貯數組,mem…系列的所有成員均操作存貯數組.在所有這些函數中,數組是 n 位元組長.memcpy 從 source 複製一個 n 位元組的塊到 destin.如果源塊和目標塊重迭,則選擇複製方向,以例正確地複製覆蓋的位元組.
void *memccpy(void *destin,void *source,unsigned char ch,unsigned n)
void *memchr(void *s,char ch,unsigned n)從 source 複製位元組到 destin.複製一結束就發生下列任一情況:(1)字元 ch 首選複製到 destin.(2)n 個位元組已複製到 destin
void *memcmp(void *s1,void *s2,unsigned n)比較正好是 n 位元組長的兩個字串 s1 和 s2.
int memicmp(void *s1,void *s2,unsigned n)比較 s1 和 s2 的前 n 個位元組,不管字元大寫或小寫
void *memmove(void *destin,void *source,unsigned n)memmove 與 memcpy 相同
void *memcpy(void *destin,void *source,unsigned n)
void *memset(void *s,char ch,unsigned n)將 s 的所有位元組置於位元組 ch 中.s 數組的長度由 n 給出
void movedata(int segsrc,int offsrc,int segdest,int offdest,unsigned numbytes)將源地址(segsrc:offsrc)處的 numbytes 個位元組複製到目標地址(segdest:offdest)
void movemem(void *source,void *destin,unsigned len)從 source 處複製一塊長 len 位元組的資料到 destin.若源地址和目標地址字串重迭,則選擇複製方向,以便正確的複製資料
void setmem(void *addr,int len,char value)把 addr 所指的塊的第一個位元組置於位元組 value 中.

str…字串操作函數
char stpcpy(char *dest,const char *src)將字串 src 複製到 dest
char strcat(char *dest,const char *src)將字串 src 添加到 dest 末尾
char strchr(const char *s,int c)檢索並返回字元 c 在字串 s 中第一次出現的位置
int strcmp(const char *s1,const char *s2)比較字串 s1 與 s2 的大小,並返回 s1-s2
char strcpy(char *dest,const char *src)將字串 src 複製到 dest
size_t strcspn(const char *s1,const char *s2)掃描 s1,返回在 s1 中有,在 s2 中也有的字元個數
char strdup(const char *s)將字串 s 複製到最近建立的單元
int stricmp(const char *s1,const char *s2)比較字串 s1 和 s2,並返回 s1-s2
size_t strlen(const char *s)返回字串 s 的長度
char strlwr(char *s)將字串 s 中的大寫字母全部轉換成小寫字母,並返迴轉換後的字串
char strncat(char *dest,const char *src,size_t maxlen)將字串 src 中最多 maxlen 個字元複製到字串 dest 中
int strncmp(const char *s1,const char *s2,size_t maxlen)比較字串 s1 與 s2 中的前 maxlen 個字元
char strncpy(char *dest,const char *src,size_t maxlen)複製 src 中的前 maxlen 個字元到 dest 中
int strnicmp(const char *s1,const char *s2,size_t maxlen)比較字串 s1 與 s2 中的前 maxlen 個字元
char strnset(char *s,int ch,size_t n)將字串 s 的前 n 個字元置於 ch 中
char strpbrk(const char *s1,const char *s2)掃描字串 s1,並返回在 s1 和 s2 中均有的字元個數
char strrchr(const char *s,int c)掃描最後出現一個給定字元 c 的一個字串 s
char strrev(char *s)將字串 s 中的字元全部顛倒順序重新排列,並返回排列後的字串
char strset(char *s,int ch)將一個字串 s 中的所有字元置於一個給定的字元 ch
size_t strspn(const char *s1,const char *s2)掃描字串 s1,並返回在 s1 和 s2 中均有的字元個數
char strstr(const char *s1,const char *s2)掃描字串 s2,並返回第一次出現 s1 的位置
char strtok(char *s1,const char *s2)檢索字串 s1,該字串 s1 是由字串 s2 中定義的定界符所分隔
char strupr(char *s)將字串 s 中的小寫字母全部轉換成大寫字母,並返迴轉換後的字串

存貯分配子程式,所在函數庫為 dos.h、 alloc.h、 malloc.h、 stdlib.h、 process.h
int allocmem(unsigned size,unsigned *seg)利用 DOS 分配閒置記憶體,size 為分配記憶體大小,seg 為分配後的記憶體指標
int freemem(unsigned seg)釋放先前由 allocmem 分配的記憶體,seg 為指定的記憶體指標
int setblock(int seg,int newsize)修改所分配的記憶體長度,seg 為已指派記憶體的記憶體指標,newsize 為新的長度
int brk(void *endds)本函數用來改變分配給調用程式的資料區段的空間數量,新的空間結束位址為 endds
char *sbrk(int incr)本函數用來增加分配給調用程式的資料區段的空間數量,增加 incr 個位元組的空間
unsigned long coreleft()本函數返回未用的儲存區的長度,以位元組為單位
void *calloc(unsigned nelem,unsigned elsize)分配 nelem 個長度為 elsize 的記憶體空間並返回所分配記憶體的指標
void *malloc(unsigned size)分配 size 個位元組的記憶體空間,並返回所分配記憶體的指標
void free(void *ptr)釋放先前所分配的記憶體,所要釋放的記憶體的指標為 ptr
void *realloc(void *ptr,unsigned newsize)改變已指派記憶體的大小,ptr 為已指派有記憶體地區的指標,newsize 為新的長度,返回分配好的記憶體指標.
long farcoreleft()返回遠堆中未用的儲存區的長度,以位元組為單位
void far *farcalloc(unsigned long units,unsigned long unitsz)從遠堆分配 units 個長度為 unitsz 的記憶體空間,並返回所分配記憶體的指標
void *farmalloc(unsigned long size)分配 size 個位元組的記憶體空間,並返回分配的記憶體指標
void farfree(void far *block)釋放先前從遠堆分配的記憶體空間,所要釋放的遠堆記憶體的指標為 block
void far *farrealloc(void far *block,unsigned long newsize)改變已指派的遠堆記憶體的大小,block 為已指派有記憶體地區的指標,newzie 為新的長度,返回分配好的記憶體指標

時間日期函數,函數庫為 time.h、 dos.h
char *ctime(long *clock)把 clock 所指的時間(如由函數 time 返回的時間)轉換成下列格式的字串:Mon Nov 21 11:31:54 1983\n\0
char *asctime(struct tm *tm)把指定的 tm 結構類的時間轉換成下列格式的字串:Mon Nov 21 11:31:54 1983\n\0
double difftime(time_t time2,time_t time1)計算結構 time2 和 time1 之間的時間差距(以秒為單位)
struct tm *gmtime(long *clock)把 clock 所指的時間(如由函數 time 返回的時間)轉換成格林威治時間,並以 tm 結構形式返回
struct tm *localtime(long *clock)本函數把 clock 所指的時間(如函數 time 返回的時間)轉換成當地標準時間,並以 tm 結構形式返回
void tzset()本函數提供了對 UNIX 作業系統的相容性
long dostounix(struct date *dateptr,struct time *timeptr)將 dateptr 所指的日期,timeptr 所指的時間轉換成 UNIX 格式,並返回自格林威治時間 1970 年 1 月 1 日淩晨起到現在的秒數
void unixtodos(long utime,struct date *dateptr,struct time *timeptr)將自格林威治時間 1970 年 1 月 1 日淩晨起到現在的秒數 utime 轉換成DOS 格式並儲存於使用者所指的結構 dateptr 和 timeptr 中
void getdate(struct date *dateblk)將電腦內的日期寫入結構 dateblk中以供使用者使用
void setdate(struct date *dateblk)本函數將電腦內的日期改成由結構 dateblk 所指定的日期
void gettime(struct time *timep)將電腦內的時間寫入結構 timep 中,以供使用者使用
void settime(struct time *timep)將電腦內的時間改為由結構 timep 所指的時間
long time(long *tloc)給出自格林威治時間 1970 年 1 月 1 日淩晨至現在所經過的秒數,並將該值存於 tloc 所指的單元中
int stime(long *tp)本函數將 tp 所指的時間(例如由 time 所返回的時間)寫入電腦中.

c++函數常用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.