缓冲输入输出

本文详细介绍了C标准库中用于文件操作的各种函数,包括文件的打开、关闭、读写及定位等基本操作,并提供了相关函数的使用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[cpp]  view plain copy
  1. 1.fopen()打开文件,返回流  
  2. FILE* fopen(const char * path, const char * mode);  
  3. 2.fdopen()通过文件描述符打开文件  
  4. FILE * fdopen (int fd, const char *mode);  
  5. 3.fclose()关闭文件  
  6. int fclose (FILE *stream);  
  7. 4.fcloseall()关闭所有文件  
  8. int fcloseall (void);  
  9. 5.fgetc()读取单个字符  
  10. int fgetc (FILE *stream);  
  11. 6.ungetc()将字符放回流  
  12. int ungetc (int c, FILE *stream);  
  13. 7.fgets()按行读取字符串  
  14. char * fgets (char *str, int size, FILE *stream);  
  15. 8.fread()读取二进制  
  16. size_t fread (void *buf, size_t size, size_t nr,FILE *stream);  
  17. 9.fputc()写入单个字符  
  18. int fputc (int c, FILE *stream);  
  19. 10.fputs()写入字符串  
  20. int fputs (const char *str, FILE *stream);  
  21. 11.fwrite()写入二进制数据  
  22. size_t fwrite (void *buf,size_t size,size_t nr,FILE *stream);  
  23. 12.定位流  
  24. fseek()函数  
  25. int fseek (FILE *stream, long offset, int whence);//将流设置到whence规定的offset处(whence的取值可以是SEEK_SET、SEEK_CUR、SEEK_END)  
  26. fsetpos()函数  
  27. int fsetpos (FILE *stream, fpos_t *pos);//将流设置到pos处  
  28. rewind()函数  
  29. void rewind (FILE *stream);//将流设置到开始位置  
  30. 13.ftell()返回当前流的位置  
  31. long ftell (FILE *stream);  
  32. 14.fgetpos()获得当前流的位置设置到pos中  
  33. int fgetpos (FILE *stream, fpos_t *pos);  
  34. 15.fflush()将数据刷到内核缓冲区中  
  35. int fflush (FILE *stream);  
  36. 16.ferror()检测错误标志  
  37. int ferror (FILE *stream);  
  38. 17.feof()检测文件结尾标志  
  39. int feof (FILE *stream);  
  40. 18.clearerr()清空错误和文件结尾标志  
  41. void clearerr (FILE *stream);  
  42. 19.fileno()获取文件描述符  
  43. int fileno (FILE *stream);  
  44. 20.setvbuf()设置一个指向buf区域size大小的缓冲,mode表示缓冲模式(_IONBF、_IOLBF、_IOFBF)  
  45. int setvbuf (FILE *stream, char *buf, int mode,size_t size);  
  46. 21.flockfile()文件加锁  
  47. void flockfile (FILE *stream);  
  48. 22.funlockfile()、ftrylockfile()减少与流相关的锁计数  
  49. void funlockfile (FILE *stream);  
  50. int ftrylockfile (FILE *stream);  
  51. 23.不加锁函数  
  52. int fgetc_unlocked (FILE *stream);  
  53. char *fgets_unlocked (char *str, int size, FILE *stream);  
  54. size_t fread_unlocked (void *buf, size_t size,size_t nr,FILE *stream);  
  55. int fputc_unlocked (int c, FILE *stream);  
  56. int fputs_unlocked (const char *str, FILE *stream);  
  57. size_t fwrite_unlocked (void *buf, size_t size,size_t nr,FILE *stream);  
  58. int fflush_unlocked (FILE *stream);  
  59. int feof_unlocked (FILE *stream);  
  60. int ferror_unlocked (FILE *stream);  
  61. int fileno_unlocked (FILE *stream);  
  62. void clearerr_unlocked (FILE *stream);  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值