帮助编写二进制文件。 [英] Help writing binary file.

查看:84
本文介绍了帮助编写二进制文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我一直在尝试这个并且无法解决它,有人可以指导我做一个例子或者告诉我我做错了什么。



 //////// 
我正在处理一些数据...获取Count的值。
long ArraySize = Count;
BYTE * FileOut;
FileOut = new BYTE [ArraySize];
///
我可以将我的数据存入文件中。
///

我在尝试将FileOut写入二进制文件时遇到问题。


FILE * file2 = NULL;
if((file2 = fopen(FileName,ab))== NULL)
{
Temp.Format(_T(无法打开指定文件));
}
else
{
fwrite(FileOut,sizeof(FileOut [0]),sizeof(FileOut)/ sizeof(FileOut [0]),file2);
}
delete [] FileOut;
fclose(file2);





任何帮助将不胜感激。





对不起我没有得到完整的数组只有4个数字。

解决方案

你的调试器是针对这类问题。



当你获取sizeof(FileOut)时,你得到的指针FileOut的大小是4个字节。



将此行更改为:



 fwrite(FileOut,< span class =code-keyword> sizeof (BYTE), sizeof (BYTE)* ArraySize,file2); 









有更正以上。它应该是:

 fwrite(FileOut, sizeof (BYTE),ArraySize,file2); 





如果将FileOut声明为int,它将正常工作,例如:



 fwrite(FileOut, sizeof  int ),ArraySize,file2) ; 


Hello,
I have been trying this and have not been able to resolve it, can someone please direct me to an example or tell me what I am doing wrong.

////////
I am processing some data...  getting a value to Count.
long ArraySize = Count;
BYTE *FileOut;
FileOut = new BYTE[ArraySize];
///
I am able to put my data into file out.
///

I am having issues trying to write FileOut to a binary file.


FILE *file2 = NULL;
if ((file2 = fopen(FileName, "ab")) == NULL)
{
	Temp.Format(_T("Could not open specified file"));
}
else
{
	fwrite(FileOut, sizeof(FileOut[0]), sizeof(FileOut)/ sizeof(FileOut[0]),file2);
}
delete[]FileOut;
fclose(file2);



Any help will be appreciated.


Sorry I am not getting the full array out only 4 numbers.

解决方案

Your debugger is for this type of problem.

When you take sizeof(FileOut) you get the size of pointer FileOut which is 4 bytes.

Change this line to:

fwrite(FileOut, sizeof(BYTE), sizeof(BYTE) * ArraySize, file2);



[Edit]

There is a correction to the above. It should read:

fwrite(FileOut, sizeof(BYTE), ArraySize, file2);



It will then work correctly if FileOut is declared as int for example:

fwrite(FileOut, sizeof(int), ArraySize, file2);


这篇关于帮助编写二进制文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆