C++ Filling a class in one rush from a file
<p>I am currently filling a class like this (which is rather slow for my purposes):</p>

<pre><code>void CBinLoader::LoadMatchesFromCompiledDat(clsMatches &amp;uMatches)
{
int size = 0;
fread(&amp;size,sizeof(int),1,m_infile);

for(int i = 0; i &lt; size; i++)
{
    MatchNode newMatch;
    newMatch.EnteredCharacter = ReadWStringFromCompiledDat(m_infile);

    int PossibleResults_size = 0;
    fread(&amp;PossibleResults_size,sizeof(int),1,m_infile);

    for(int j=0; j&lt;PossibleResults_size; j++)
    {
        PossibleResult pr;

        fread(&amp;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(&amp;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(&amp;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;
}
</code></pre>

<p>Is it possible to just read it in in one rush instead of filling it up piece by piece?</p>
