Chinaunix首页 | 论坛 | 博客
  • 博客访问: 276550
  • 博文数量: 28
  • 博客积分: 690
  • 博客等级: 上士
  • 技术积分: 358
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-25 20:39
文章分类

全部博文(28)

文章存档

2012年(12)

2011年(16)

分类: C/C++

2012-03-06 09:23:55

C 读写文件:
              File *fp;
              fp = fopen(const char* filename, const char* mode);  //mode = "r" "w"  "a" "r+"  "w+"
              int fputc(int a, fp);  //put a char to fp, and return the value of a
              char c = fgetc(fp);  //
              int fseek(fp, int offset, int whence);
              fputs(char *, fp);
              fgets(str, int size, fp);
              fprintf(fp, fmt, arguments);
              fscanf(fp, fmt, &arguments);

               fread(void *ptr, size_t size, size_t n, fp);
               fwrite(const void* ptr, size_t size, n, fp);             
 
C++读写文件:
           读:ifstream if("a.txt");
                  或者
                  ifstream if;
                  if.open("a.txt");
 
                  if>>variable; //空格作为结束符
                  if.getline(string line);
                  getline(if,string line );

           写:ofstream if("a.txt");
                  或者
                  ofstream if;
                  of.open("a.txt");
 
                  of<
阅读(2162) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~