printf,fprintf,dprintf,sprintf,snprintf 区别笔记

printf,fprintf,dprintf,sprintf,snprintf 区别笔记

文章目录

  • printf,fprintf,dprintf,sprintf,snprintf 区别笔记
    • 函数原型
    • printf
    • fprintf
    • dprintf
    • sprintf
    • snprintf
    • vprintf
    • vfprintf
    • vdprintf
    • vsprintf
    • vsnprintf

写过多少次 printf(“Hello World!”);
但是printf的兄弟们您了解么?

函数原型

#include 

int printf(const char *restrict format, ...);
int fprintf(FILE *restrict stream, const char *restrict format, ...);
int dprintf(int fd, const char *restrict format, ...);
int sprintf(char *restrict str, const char *restrict format, ...);
int snprintf(char *restrict str, size_t size, const char *restrict format, ...);
#include 

int vprintf(const char *restrict format, va_list ap);
int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap);
int vdprintf(int fd, const char *restrict format, va_list ap);
int vsprintf(char *restrict str, const char *restrict format, va_list ap);
int vsnprintf(char *restrict str, size_t size, const char *restrict format, va_list ap);

printf

int printf(const char *restrict format, ...);
输出到stdout标准化输出

fprintf

int fprintf(FILE *restrict stream, const char *restrict format, ...);
输出到stream文件流

dprintf

int dprintf(int fd, const char *restrict format, ...);
输出到fd文件描述符

sprintf

int sprintf(char *restrict str, const char *restrict format, ...);
va_​​list格式参数输出到str字符指针

snprintf

int snprintf(char *restrict str, size_t size, const char *restrict format, ...);
输出到str字符指针(指定长度)

vprintf

int vprintf(const char *restrict format, va_list ap);
va_​​list样式的参数列表,输出到stdout标准化输出

vfprintf

int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap);
va_​​list样式的参数列表,输出到stream文件流

vdprintf

int vdprintf(int fd, const char *restrict format, va_list ap);
va_​​list样式的参数列表,输出到fd文件描述符

vsprintf

int vsprintf(char *restrict str, const char *restrict format, va_list ap);
va_​​list样式的参数列表,输出到str字符指针

vsnprintf

int vsnprintf(char *restrict str, size_t size, const char *restrict format, va_list ap);
va_​​list样式的参数列表,输出到str字符指针(指定长度)

你可能感兴趣的:(C/C++)