C++文件操作

https://blog.csdn.net/shenziheng1/article/details/79472102

 #include<stdio.h>

C++ fopen/fwrite/fread

 

文件写入:

FILE * fp;
fp = fopen("data.txt","w");
if (fp != NULL)
{
  fwrite(data, sizeof(char), size, fp); 
  fclose(fp);
}

 

文件读取:

 

FILE * fp;
fp = fopen("/home/leinao/test/myfile.txt","r");
if (fp != NULL)
{
    size_t bytes_read = fread(data, sizeof(char), size, fp);
    printf("Read Bytes: %d\n", bytes_read);
    fclose(fp);
}

 

 

 

posted on 2019-11-15 20:53  穷酸秀才大草包  阅读(103)  评论(0编辑  收藏  举报

导航