文件操作小结

Posted on 2007-12-13 17:37 T.S Liu 阅读(216) 评论(0)  编辑 收藏 引用 所属分类: C++

文件操作总是用的不是很好,今天总结一下它可用的函数!

FILE *fp = NULL;

FILE * fopen(char *filename, char *openmode)                                 打开文件

int fclose(FILE * fp)                                                                         关闭文件

int fseek(FILE *fp, long offset,  int base)                                           文件定位

void rewind(FILE *fp)                                                                      文件指针回到文件头

long ftell(FILE *fp)                                                                           返回fp所指文件读写位置

int fgetc(FILE *fp)                                                                            从fp所指文件读1个char

char * fgets(char *buffer, int n, FILE *fp)                                          从fp所指文件读n个char

int fputc(char ch, FILE *fp)                                                               向fp所指文件写1个char

int fputs(char * str, FILE *fp)                                                            向fp所指文件写n个char

int fread(char *buffer, int size, int n, FILE *fp)                                   从fp所指文件读n个size到buffer

int fwrite(char *str,  int  size , int n, FILE *fp)                                     把str指向的n*size char写到文件

int fscanf(FILE *fp, char *format, args......)                                       从fp所指文件按format格式将数据读到args所指的内存单元内!

int fprintf(FILE *fp, char *format, args......)                                       把args的值按format所指的格式写到fp所指的文件中

int feof(FILE *fp)                                                                             检查文件是否结束, 结束就反回非0值

int ferror(FILE *fp)                                                                           检查文件是否出错,没有出错时反回0

void clearerr(FILE *fp)                                                                      使fp所指的文件的错误,标志和文件结束等置


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理