请问以下代码怎么改成c++?尤其是从文件读入一个字符那,不用fscanf的写法

//将文件codefile中的代码进行译码,结果存入文件textfile中

void Decoding()

{

FILE *fp,*fw;

int m,i;

char *code,*text,*p;

 

    if(n==0)

   n=Read_tree(HT);//从文件hfmtree.txt中读入赫夫曼树,返回叶子结点数

 

if((fp=fopen("codefile.txt","rb"))==NULL)

   printf("Open file codefile.txt error!\n");

   if((fw=fopen("textfile.txt","wb+"))==NULL)

   printf("Open file textfile.txt error!\n");

code=(char *)malloc(sizeof(char));

fscanf(fp,"%c",code);        //从文件读入一个字符

for(i=1;!feof(fp);i++)

{

   code=(char *)realloc(code,(i+1)*sizeof(char));   //增加空间

   fscanf(fp,"%c",&code[i]);     //从文件读入下一个字符

}

code[i-1]='\0';

// codefile.txt文件中的字符已全部读入,存放在code数组中

    text=(char *)malloc(100*sizeof(char));

p=text;

    m=2*n-1;

if(*code=='0')

   find(HT,code,text,HT[m].lchild,m);   //从根节点的左子树去找

else

   find(HT,code,text,HT[m].rchild,m);   //从根节点的右子树去找

 

    for(i=0;p[i]!='\0';i++)    //把译码好的字符存入文件textfile.txt中

   fputc(p[i],fw);

 

fclose(fp);

fclose(fw);

 

printf("\n已将codefile.txt文件成功译码,兵已存入textfile.txt文件!\n\n");

}