zoukankan      html  css  js  c++  java
  • 第5章标准I/O库总结

    1 fwide函数试图设置流的定向(流的定向决定了读写单字节还是多字节字符)

    int fwide(FILE *fp,int mode)
                      宽定向返回正值,字节定向返回负值,为定向返回0
                       已定向流不会改变流的定向


    2 setbuf函数中指定的缓冲区的长度为BUFSIZ,这个常量在stdio.h中定义

    3 freopen和fdopen函数

    FILE *freopen(char *pathname,const char *type,FILE *fp)
    
    FILE *fdopen(int filedes,const char *type)

    3 gets和fgets、puts和fputs函数

    char *fgets(char *buf,int n,FILE *fp)
    
    char *gets(char *buf)
    
    int fputs(const char *str,FILE *fp)
    
    int puts(const char *str)

    gets函数无法指定缓冲区长度,可能导致写到缓冲区之后的存储空间中
    puts函数会添加一个换行符

    4 二进制I/O

    size_t fread(void *buf,size_t size,size_t n,FILE *fp)
    
    size_t fwrite(const void *ptr,size_t size,size_t n,FILE *fp)

    5 定位流
    流中的位置可以用long、off_t、fpos_t三种类型表示,对应有三种定位、设置流当前位置的函数

    long:

    long ftell(FILE *fp)
    
    int fseek(FILE *fp,long offset,int whence)

    off_t:

    off_t ftell(FIEL *fp)
    
    int fseeko(FILE *fp,off_t offset,int whence)

    pos_t:

    int fgetpos(FILE *fp,fpos_t *pos)
    
    int fsetpos(FILE *fp,const fpos_t *pos)

    6 格式化I/O

    格式化输出:printf、fprintf、sprintf、snprintf(相比于sprintf,可以指定缓冲区长度n,超出长度将溢出)

          vprintf、vfprintf、vsprintf、vsnprintf

    格式化输入:scanf、fscanf、sscanf

          vscanf、vfscanf、vsscanf

  • 相关阅读:
    关于禁用发布可能出现的问题处理
    SQL Server数据库的整理优化的基本过程(一)
    分享SQL2005分区实现教程
    Oracle数据库的测试用户Scott的密码为什么是Tiger?
    这就是传说中的搜狗浏览器2.0
    IE6,IE7下双倍边距续
    IE7下fload:left造成双倍边距BUG
    as2和as3之间交互
    倒计时效果
    js拖动层效果
  • 原文地址:https://www.cnblogs.com/buptlyn/p/4142074.html
Copyright © 2011-2022 走看看