c/c++ _read() 和 _write() 和 _lseeki64() 和 read() 和 read() 函数

1. _read() + _write() + _lseeki64()

   ①. char lpBuf[4] = "";

         int fd; //句柄
         int readlength = 0;//读取到的长度

         int nbytes = 4;//nbytes是想要读取的长度(为4字节)
         readlength = _read(fd, lpBuf, nbytes);//读取fd指向的文件,读取4字节到lpBuf中

   ②.string data;

         int len;

         _write(fd,data.c_str(), len);//将字节长度为len内容为data的信息写进fd句柄指向的文件中

   ③. _lseeki64(fd, pos, SEEK_SET);//从文件开头移动pos位置,并返回在64位整数的偏移量


2. read

        #include <unistd.h>

        ssize_t read(int fd, void *buf, size_t nbytes);
 
        返回值: 读取到的字节数;  0(读到 EOF);  -1(出错).

        注意: read 函数从 fd 指定的已打开文件中读取 nbytes 字节到 buf 中.


3. write

   #include <unistd.h>

   ssize_t write(int fd, const void *buf, size_t nbytes);
 
   返回值: 写入文件的字节数(成功);  -1(出错).

   注意: write 函数向 fd 中写入 nbytes 字节数据, 数据来源为 buf . 返回值一般总是等于 nbytes, 否则就是出错了. 常见出错原因是磁盘空间满了或者超过了文件大小限制.




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
所有的 C / C++ 函数 Constructors (cppstring) Constructors (cppvector) Operators (cppbitset) Operators (cppdeque) Operators (cppstack) Operators (cppstring) Operators (cppvector) abort (stdother) abs (stdmath) acos (stdmath) any (cppbitset) append (cppstring) asctime (stddate) asin (stdmath) assert (stdother) assign (cppdeque) assign (cpplist) assign (cppstring) assign (cppvector) at (cppdeque) at (cppstring) at (cppvector) atan (stdmath) atan2 (stdmath) atexit (stdother) atof (stdstring) atoi (stdstring) atol (stdstring) back (cppdeque) back (cpplist) back (cppqueue) back (cppvector) bad (cppio) begin (cppdeque) begin (cpplist) begin (cppmap) begin (cppmultimap) begin (cppmultiset) begin (cppset) begin (cppstring) begin (cppvector) bsearch (stdother) c_str (cppstring) calloc (stdmem) capacity (cppstring) capacity (cppvector) ceil (stdmath) clear (cppdeque) clear (cppio) clear (cpplist) clear (cppmap) clear (cppmultimap) clear (cppmultiset) clear (cppset) clear (cppvector) clearerr (stdio) clock (stddate) compare (cppstring) copy (cppstring) cos (stdmath) cosh (stdmath) count (cppbitset) count (cppmap) count (cppmultimap) count (cppmultiset) count (cppset) ctime (stddate) data (cppstring) #define (preproc) difftime (stddate) div (stdmath) empty (cppdeque) empty (cpplist) empty (cppmap) empty (cppmultimap) empty (cppmultiset) empty (cpppriorityqueue) empty (cppqueue) empty (cppset) empty (cppstack) empty (cppstring) empty (cppvector) end (cppdeque) end (cpplist) end (cppmap) end (cppmultimap) end (cppmultiset) end (cppset) end (cppstring) end (cppvector) eof (cppio) equal_range (cppmap) equal_range (cppmultimap) equal_range (cppmultiset) equal_range (cppset) erase (cppdeque) erase (cpplist) erase (cppmap) erase (cppmultimap) erase (cppmultiset) erase (cppset) erase (cppstring) erase (cppvector) #error (preproc) exit (stdother) exp (stdmath) fabs (stdmath) fail (cppio)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值