24,854
社区成员
发帖
与我相关
我的任务
分享
int PtTree::SaveToFile(LPCTSTR Filename)
{
// ::DeleteFile(Filename);
//情况内容,
HANDLE hIndex = ::CreateFile(
Filename
,GENERIC_WRITE
,0
,NULL
,TRUNCATE_EXISTING
,FILE_ATTRIBUTE_NORMAL
,NULL);
//打开成功但就是没有把文件更新
if( INVALID_HANDLE_VALUE == hIndex )
{
ShowError();
return 0;
}
DWORD dwNumberOfBytes;
::SetFilePointer( hIndex, 0, 0 , FILE_BEGIN );
//写入节点个数
if(0 == WriteFile( hIndex, (LPVOID) &NodeCount, sizeof(NodeCount), &dwNumberOfBytes, NULL ) )
{
ShowError();
CloseHandle(hIndex);
return 0 ;
}
//写入叶子节点个数
if(0 == WriteFile( hIndex, (LPVOID)&LeafCount, sizeof(LeafCount), &dwNumberOfBytes, NULL ) )
{
ShowError();
CloseHandle(hIndex);
return 0 ;
}
//写入顺序树信息 ,这里在单步的时候可以看到dwNumberOfBytes为500,但文件的大小还是原来的248B
if(NodeCount && 0 == WriteFile( hIndex, (LPVOID)( &node), (NodeCount) * sizeof(PtNode), &dwNumberOfBytes, NULL ) )
{
ShowError();
CloseHandle(hIndex);
return 0 ;
}
//写入叶子数组
if(LeafCount && 0 == WriteFile( hIndex, (LPVOID)(&Leaf), (LeafCount) * sizeof(int), &dwNumberOfBytes, NULL ) )
{
ShowError();
CloseHandle(hIndex);
return 0 ;
}
CloseHandle(hIndex);
return 1;
}