c/c++创建并读取文本文件内容

 ///创建tuopu.txt文本,并往文本里写入数字3//

       FILE *fp;
        if((fp=fopen("tuopu.txt","wb+"))==NULL)
        {
          printf("error\n");
          exit(0);
        }
        fwrite("3",1,1,fp);
        fclose(fp);

 

///读取tuopu.txt文本//

        FILE *fp1;
        if((fp1=fopen("tuopu.txt","r"))==NULL)
        {
          printf("error\n");
          exit(0);
        }
        char result;
        fread(&result,1,1,fp1);
        printf("",result);
        fclose(fp1);

你可能感兴趣的:(c++)