c++读写文件

读取文件:

#include <stdio.h>

void read()
{
    FILE* f = fopen("E:/Desktop/1.jpg", "rb");
    fseek(f, 0, SEEK_END);
    long size = ftell(f);
    rewind(f);
    unsigned char* data = new unsigned char[size];
    fread(data, sizeof(char), size, f);
    fclose(f);
}

写入文件:

#include <stdio.h>

int main ()
{
  FILE * pFile;
  char buffer[] = { 'x' , 'y' , 'z' };
  pFile = fopen ("myfile.bin", "wb");
  fwrite (buffer , sizeof(char), sizeof(buffer), pFile);
  fclose (pFile);
  return 0;
}

 

posted on 2021-01-19 14:20  空明流光  阅读(137)  评论(0编辑  收藏  举报

导航