zoukankan      html  css  js  c++  java
  • 文件IO函数

    creat函数创建一个新文件:

    #include <fcntl.h>
    int creat( const char *pathname, mode_t mode );

     返回值:若成功则返回为只写打开的文件描述符,若出错则返回-1;

     

    open 函数用于打开和创建文件:
    #include <fcntl.h>
    int open(const char *pathname, int oflag, ... /* mode_t mode */);
    返回值:成功则返回文件描述符,否则返回 -1

     

    close函数关闭一个打开的文件:

    #include <unistd.h>
    int close( int filedes );

    返回值:若成功则返回0,若出错则返回-1;

     

    lseek函数为一个打开的文件设置其偏移量:

    #include <unistd.h>
    off_t lseek( int filedes, off_t offset, int whence );

    返回值:若成功则返回新的文件偏移量,若出错则返回-1;

     

    read函数从打开文件中读数据:

    #include <unistd.h>
    ssize_t read( int filedes, void *buf, size_t nbytest );

    返回值:若成功则返回读到的字节数,若已读到文件结尾则返回0,若出错则返回-1;

     

    write函数向打开的文件写数据:

    #include <unistd.h>
    ssize_t write( int filedes, const void *buf, size_t nbytes );

    返回值:若成功则返回已写的字节数,若出错则返回-1。

  • 相关阅读:
    flask-离线脚本、with在上下文的应用
    websocket原理及实时投票
    微信消息的推送
    Django + Uwsgi + Nginx 的生产环境部署2
    UVA 11853 Paintball
    UVA 12171 Sculpture
    UVA 10305 Ordering Tasks
    UVA 816 Abbott's Revenge
    UVA 699 The Falling Leaves
    UVA 12657 Boxes in a Line
  • 原文地址:https://www.cnblogs.com/hezhangyear/p/4021216.html
Copyright © 2011-2022 走看看