如果二进制文件无效,则停止工作 [英] stop work if invalide binary file
问题描述
大家好,
我目前正在我的mfc项目中实现二进制文件读取.
cocept工作得很好,但是输入错误的二进制文件出现了问题.
就像下面的
我的二进制文件应包含,
标头4个字节
10个字节的数据,如
名称从5到10个字节不等.
现在,当我输入的文件错误时仅包含5个字节时,我得到了断言
因为我排除了15个字节,所以可以从此错误中得到什么
谢谢
Hi all,
I''m currently implementating binary file reading in my mfc project.
cocept work so fine but problem arises for wrong input binary file.
like below
my binary file should contain,
4 bytes of header
10 bytes data like
name varies from 5 to 10 bytes.
now when i wrong intput file contain only 5 bytes i got assertion
because i excepted 15 bytes so what is alternative to come out of this error
thanks
推荐答案
现在我输入文件错误时仅包含我断言了5个字节
因为我排除了15个字节,所以可以从此错误中找到另一种方法
now when i wrong intput file contain only 5 bytes i got assertion
because i excepted 15 bytes so what is alternative to come out of this error
当然,另一种方法是在实际解析
之前检查文件长度.
文件.
The alternative, of course, is checking the file length before actually parsing the
file.
您还没有说过要进行读取的内容.代码会很好,但是...
C具有_lseek()来执行此操作,而CFile具有GetLength().不知道正在读取的文件的长度会导致您一遍又一遍的问题.这是您应该非常防御地编程的一个很好的例子.否则,您将有许多错误等待着您进入代码.
You have not said what you are using to do the read. Code would be nice, but...
C has _lseek() to do that and CFile has GetLength(). Not knowing the length of a file you are reading is going to cause you problems over and over again. This is a good example of an area that you should program quite defensively. Otherwise, you will have many bugs waiting to get you in your code.
这篇关于如果二进制文件无效,则停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!