您的位置:程序门 -> vc/mfc -> 基础类



如何验证读取二进制文件数据的正确性?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何验证读取二进制文件数据的正确性?[已结贴,结贴人:yqcai1000]
发表于:2007-03-01 11:43:10 楼主
大家好,本人是菜鸟,有以下疑问,
cstring   szfilename   =   filedlg.getnextpathname(pos);  
char   *pbuf;
cfile   file;
file.open(szfilename,cfile::moderead ¦cfile::typebinary);
dword   dwfilelen;
dwfilelen=file.getlength();
pbuf=new   char[dwfilelen+1];
pbuf[dwfilelen]=0;
file.read(pbuf,dwfilelen);
int   temp   =   atoi(pbuf);
file.close();
cstring   tempstring;
tempstring.format( "%d ",temp);
messagebox(pbuf);
messagebox(tempstring);

1.二进制文件以文本方式打开是乱码,读取后用messagebox显示的和文本是一样,也是乱码,可我要读取的是灰度值,应该是数字才对啊。
2.如何显示这些数字,为什么temp总是0,希望老手们帮忙啊
发表于:2007-03-01 11:47:451楼 得分:10
int   temp   =   atoi(pbuf);

-> >

memcpy(&temp,   pbuf,   4)
发表于:2007-03-01 12:32:192楼 得分:0
谢谢,能解释一下么?
发表于:2007-03-01 12:35:023楼 得分:10
你是以二进制方式打开的文件,读取出来的是数值类型,而不是字符类型,所以用atoi是行不通的。
直接进行内存复制操作


快速检索

最新资讯
热门点击