Read为什么没有读出内容?

时间:2008-05-22 08:59:15   来源:论坛整理  作者:  编辑:chinaitzhe
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct TagTcpHead   //DAT文件格式
{
unsigned char flag[2]; // 标志,必须为:0x55AA
unsigned char linkName;
unsigned char linkType;
unsigned char sTime[5];
short int len; // 后续数据长度
unsigned char *data; //后续数据
};

void GetData(ifstream& rb,TagTcpHead& TTH);
void ShowData(ofstream& wb,TagTcpHead& Tag);
int main()
{
TagTcpHead Head;
ifstream ReadBin;
ReadBin.open("20080201100830.dat");
ofstream WriteBin;
WriteBin.open("text.bin",ios::out ¦ios::binary);

for(int i=0;i <10;i )
{
GetData(ReadBin,Head);
ShowData(WriteBin,Head);
}

ReadBin.close();
WriteBin.close();

cout < < "Test Compltet";

return 0;

}
/*===================== GetData ==================*/
void GetData(ifstream& rb,TagTcpHead& TTH)
{
cout < <"Begin Read......\n";
rb.read((char*)&TTH.flag, sizeof(&TTH.flag));
rb.read((char*)&TTH.linkName,sizeof(&TTH.linkName));
rb.read((char*)&TTH.linkType,sizeof(&TTH.linkType));
rb.read((char*)&TTH.sTime, sizeof(&TTH.sTime));
rb.read((char*)&TTH.len, sizeof(&TTH.len));
rb.read((char*)&TTH.data, (int)&TTH.len);
//屏幕显示

cout < < "flag:" < < &TTH.flag < < "\n";
cout < < "linkName" < < &TTH.linkName < < "\n";
cout < < "linkType" < < &TTH.linkType < < "\n";
cout < < "sTime" < < &TTH.sTime < < "\n";
cout < < "len" < < &TTH.len < < "\n";
cout < < "data" < < &TTH.data < < "\n";
}
/*=================== ShowData ===================*/
void ShowData(ofstream& wb,TagTcpHead& Tag)
{
//屏幕显示
cout < < "Begin Write......\n";
cout < < "flag:" < < &Tag.flag < < "\n";
cout < < "linkName" < < &Tag.linkName < < "\n";
cout < < "linkType" < < &Tag.linkType < < "\n";
cout < < "sTime" < < &Tag.sTime < < "\n";
cout < < "len" < < &Tag.len < < "\n";
cout < < "data" < < &Tag.data < < "\n";
//文件输出
wb.write((char*) &Tag,sizeof(TagTcpHead));

}

问题:程序运行到read时退出,没有读出内容
屏幕显示:Begin Read......,
请教高手帮忙解答一下,
如有需要DAT文件可与本人联系,QQ号:12100644,


网友回复:rb.read((char*)TTH.flag, sizeof(TTH.flag));
关键字:Read,没有,读出,内容,

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面