Índice
- string cstring e cópia de memória
- strings cstdlib e alocação de memória
- entrada e saída cstdio
- funções matemáticas cmath
- função de tempo ctime
1 arquivo de cabeçalho cstring
#include<cstring>
função | descrever |
---|---|
void *memchr(const void *str, int c, size_t n) | Procura a primeira ocorrência do caractere c (um unsigned char) nos primeiros n bytes da string apontada pelo parâmetro str. |
int memcmp(const void *str1, const void *str2, size_t n) | Compara os primeiros n bytes de str1 e str2. |
void *memcpy(void *dest, const void *src, size_t n) | Copie n caracteres de src para dest. |
void *memmove(void *dest, const void *src, size_t n) | Outra função para copiar n caracteres de src para dest. |
void *memset(void *str, int c, size_t n) | Copia o caractere c (um unsigned char) para os primeiros n caracteres da string apontada pelo parâmetro str. |
char *strcat(char *dest, const char *src) | Acrescenta a string apontada por src ao final da string apontada por dest. |
char *strncat(char *dest, const char *src, size_t n) | Acrescenta a string apontada por src ao final da string apontada por dest, até n caracteres de comprimento. |
char *strchr(const char *str, int c) | Procura a primeira ocorrência do caractere c (um unsigned char) na string apontada pelo parâmetro str. |
int strcmp(const char *str1, const char *str2) | Compara a string apontada por str1 com a string apontada por str2. |
int strncmp(const char *str1, const char *str2, size_t n) | Compare str1 e str2 até os primeiros n bytes. |
int strcoll(const char *str1, const char *str2) | Compare str1 e str2, o resultado depende da configuração de posição de LC_COLLATE. |
char *strcpy(char *dest, const char *src) | Copie a string apontada por src para dest. |
char *strncpy(char *dest, const char *src, size_t n) | Copie a string apontada por src para dest, até n caracteres. |
size_t strcspn(const char *str1, const char *str2) | Pesquise vários caracteres consecutivos no início da string str1 que não contenham os caracteres da string str2. |
char *estrerror(int errnum) | Procura o número do erro errnum na matriz interna e retorna um ponteiro para a string da mensagem de erro. |
size_t strlen(const char *str) | Calcula o comprimento da string str até, mas não incluindo, o caractere de terminação nula. |
char *strpbrk(const char *str1, const char *str2) | Recupera o primeiro caractere na string str1 que corresponde a um caractere na string str2, excluindo o caractere de terminação nula. Ou seja, verifique os caracteres na string str1 sucessivamente e, quando o caractere verificado também estiver incluído na string str2, pare de verificar e retorne a posição do caractere. |
char *strrchr(const char *str, int c) | Procura a última ocorrência do caractere c (um unsigned char) na string apontada pelo parâmetro str. |
size_t strspn(const char *str1, const char *str2) | Recupera o índice do primeiro caractere na string str1 que não ocorre na string str2. |
char *strstr(const char *palheiro, const char *agulha) | Localiza a primeira ocorrência da agulha da string (sem incluir o caractere de terminação nula) no palheiro da string. |
char *strtok(char *str, const char *delim) | Decompõe a string str em um conjunto de strings com delim como delimitador. |
size_t strxfrm(char *dest, const char *src, size_t n) | Converte os primeiros n caracteres da string src de acordo com LC_COLLATE na localidade atual do programa e os coloca na string dest. |
2 arquivo de cabeçalho cstdlib
#include<cstdlib>
correlação de string
função | descrever |
---|---|
duplo atof(const char *str) | Converta a string apontada pelo parâmetro str em um número de ponto flutuante (tipo double). |
int atoi(const char *str) | Converta a string apontada pelo parâmetro str em um inteiro (o tipo é int). |
long int atol(const char *str) | Converta a string apontada pelo parâmetro str em um inteiro longo (o tipo é long int). |
double strtod(const char *str, char **endptr) | Converta a string apontada pelo parâmetro str em um número de ponto flutuante (tipo double). |
long int strtol(const char *str, char **endptr, int base) | Converta a string apontada pelo parâmetro str em um inteiro longo (o tipo é long int). |
unsigned long int strtoul(const char *str, char **endptr, int base) | Converta a string apontada pelo parâmetro str para um inteiro longo sem sinal (o tipo é int longo sem sinal). |
alocação de memória
função | descrever |
---|---|
void *calloc(size_t nitens, size_t size) | Aloca o espaço de memória necessário e retorna um ponteiro para ele. |
void livre(void *ptr) | Libera espaço de memória alocado por uma chamada anterior para calloc, malloc ou realloc. |
void *malloc(size_t size) | 分配所需的内存空间,并返回一个指向它的指针。 |
void *realloc(void *ptr, size_t size) | 尝试重新调整之前调用 malloc 或 calloc 所分配的 ptr 所指向的内存块的大小。 |
随机数
函数 | 描述 |
---|---|
int rand(void) | 返回一个范围在 0 到 RAND_MAX 之间的伪随机数。 |
void srand(unsigned int seed) | 该函数播种由函数 rand 使用的随机数发生器。 |
系统函数
函数 | 描述 |
---|---|
void abort(void) | 使一个异常程序终止。 |
int atexit(void (*func)(void)) | 当程序正常终止时,调用指定的函数 func。 |
void exit(int status) | 使程序正常终止。 |
char *getenv(const char *name) | 搜索 name 所指向的环境字符串,并返回相关的值给字符串。 |
int system(const char *string) | 由 string 指定的命令传给要被命令处理器执行的主机环境。 |
3 头文件cstdio
#include<cstdio>
文件函数
- File access:
函数 | 描述 |
---|---|
fclose | |
Close file (function ) | |
fflush | |
Flush stream (function ) | |
fopen | |
Open file (function ) | |
freopen | |
Reopen stream with different file or mode (function ) | |
setbuf | |
Set stream buffer (function ) | |
setvbuf | |
Change stream buffering (function ) |
- Direct input/output:
函数 | 描述 |
---|---|
fread | |
Read block of data from stream (function ) | |
fwrite | |
Write block of data to stream (function ) |
- File positioning:
函数 | 描述 |
---|---|
fgetpos | |
Get current position in stream (function ) | |
fseek | |
Reposition stream position indicator (function ) | |
fsetpos | |
Set position indicator of stream (function ) | |
ftell | |
Get current position in stream (function ) | |
rewind | |
Set position of stream to the beginning (function ) |
- Error-handling:
函数 | 描述 |
---|---|
clearerr | |
Clear error indicators (function ) | |
feof | |
Check end-of-file indicator (function ) | |
ferror | |
Check error indicator (function ) | |
perror | |
Print error message (function ) |
格式化输入输出函数
Formatted input/output:
函数 | 描述 |
---|---|
fprintf | |
Write formatted data to stream (function ) | |
fscanf | |
Read formatted data from stream (function ) | |
printf | |
Print formatted data to stdout (function ) | |
scanf | |
Read formatted data from stdin (function ) | |
snprintf | |
Write formatted output to sized buffer (function ) | |
sprintf | |
Write formatted data to string (function ) | |
sscanf | |
Read formatted data from string (function ) | |
vfprintf | |
Write formatted data from variable argument list to stream (function ) | |
vfscanf | |
Read formatted data from stream into variable argument list (function ) | |
vprintf | |
Print formatted data from variable argument list to stdout (function ) | |
vscanf | |
Read formatted data into variable argument list (function ) | |
vsnprintf | |
Write formatted data from variable argument list to sized buffer (function ) | |
vsprintf | |
Write formatted data from variable argument list to string (function ) | |
vsscanf | |
Read formatted data from string into variable argument list (function ) |
字符输入输出函数
Character input/output:
函数 | 描述 |
---|---|
fgetc | |
Get character from stream (function ) | |
fgets | |
Get string from stream (function ) | |
fputc | |
Write character to stream (function ) | |
fputs | |
Write string to stream (function ) | |
getc | |
Get character from stream (function ) | |
getchar | |
Get character from stdin (function ) | |
gets | |
Get string from stdin (function ) | |
putc | |
Write character to stream (function ) | |
putchar | |
Write character to stdout (function ) | |
puts | |
Write string to stdout (function ) | |
ungetc | |
Unget character from stream (function ) |
5 头文件ctime
#include<ctime>
函数 | 描述 |
---|---|
char *asctime(const struct tm *timeptr) | 返回一个指向字符串的指针,它代表了结构 timeptr 的日期和时间。 |
clock_t clock(void) | 返回程序执行起(一般为程序的开头),处理器时钟所使用的时间。 |
struct tm *gmtime(const time_t *timer) | timer 的值被分解为 tm 结构,并用协调世界时(UTC)也被称为格林尼治标准时间(GMT)表示。 |
struct tm *localtime(const time_t *timer) | timer 的值被分解为 tm 结构,并用本地时区表示。 |
time_t mktime(struct tm *timeptr) | 把 timeptr 所指向的结构转换为一个依据本地时区的 time_t 值。 |
size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr) | 根据 format 中定义的格式化规则,格式化结构 timeptr 表示的时间,并把它存储在 str 中。 |
time_t time(time_t *timer) | 计算当前日历时间,并把它编码成 time_t 格式。 |