我目前正在填写这样的课程(就我的目的而言,这相当慢):
void CBinLoader::LoadMatchesFromCompiledDat(clsMatches &uMatches)
{
int size = 0;
fread(&size,sizeof(int),1,m_infile);
for(int i = 0; i < size; i++)
{
MatchNode newMatch;
newMatch.EnteredCharacter = ReadWStringFromCompiledDat(m_infile);
int PossibleResults_size = 0;
fread(&PossibleResults_size,sizeof(int),1,m_infile);
for(int j=0; j<PossibleResults_size; j++)
{
PossibleResult pr;
fread(&pr.LenToUseFromEnteredString, sizeof(int), 1, m_infile);
pr.Trans = ReadWStringFromCompiledDat(m_infile);
pr.NextChars = ReadWStringFromCompiledDat(m_infile);
pr.PrevTrans = ReadWStringFromCompiledDat(m_infile);
pr.PrevPrevTrans = ReadWStringFromCompiledDat(m_infile);
fread(&pr.SequenceID, sizeof(int), 1, m_infile);
newMatch.PossibleResults.push_back(pr);
}
uMatches.Content().push_back(newMatch);
}
}
wstring CBinLoader::ReadWStringFromCompiledDat(FILE *pFile)
{
//read the length of the string
int len = 0;
fread(&len, sizeof(int), 1, m_infile);
//make buffer with this length
wchar_t* pBuffer = NULL;
pBuffer = new wchar_t[len+1];
memset(pBuffer, 0, (len+1)*sizeof(wchar_t));
//read the string into the buffer
fread(pBuffer, sizeof(wchar_t), len, m_infile);
wstring result = pBuffer;
delete pBuffer;
return result;
}
是否可以一口气读完而不是一块一块地填满?