I'm trying to compile this code, and I get a pop up on my screen saying something like this:
*************************************
DEBUG ASSERTION FAILED!

Pogram: "my program"

File: f:\... \dbgdel.cpp
Line: 52

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

*************************************

I know that reading from the binary file is causing the problem LINE 148(I removed the line from the code and everythig works fine) .. in fact, with out removing that line all the operations are succesfully executed... when using the debugger, the program stops on the return0; line from main()... I HOPE SOMEONE COULD HELP!!

*************************************

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

#define MAXBUCKETS 30
#define MAXSLOTS 3
#define OVERFLOW 10


template <class KEY, class DATA>
class SLOT
{
protected:
KEY key;
DATA data;
public:

KEY GetKey ()
{ return key; }

DATA GetData ()
{return data; }

void SetKey(KEY k)
{ key = k; }

void SetData(DATA d)
{ data = d; }
};


template <class SLOTS, class KEY, class DATA>
class BUCKET : private SLOT <string, string>
{
protected:
SLOTS ht_slot[MAXSLOTS];
unsigned int count;
unsigned short int overflow;

public:


BUCKET ()
{ count = overflow = 0;}

unsigned int GetCount()
{ return count; }

unsigned short int GetOverflow()
{ return overflow; }

void SetSlot(int i, KEY k, DATA d)
{
ht_slot[i].SetKey(k);
ht_slot[i].SetData(d);
cout << ht_slot[i].GetKey()<< endl;
}

KEY GetSlotKey (int i)
{ return ht_slot[i].GetKey(); }




void SetCount (unsigned int c)
{ count = c; }

void AddCount ()
{ count = ++count; }

void SetOverflow (unsigned int o)
{ overflow = o; }


};


class HT : private BUCKET<SLOT<string, string>, string, string>
{
protected:
BUCKET hash_table[MAXBUCKETS];
int index, collisions;
string tempdata;
bool stored;

void WriteToSlot(int index);

public:

HT()
{
index = collisions = 0;
tempdata.clear();
stored = false;
}

void HT::InsertData (fstream &DATAFILE);



int Hash (string s);

void SetSlot (int b_i, int s_i, string k, string d)
{
hash_table[b_i].SetSlot(s_i,k,d);
}

string GetKey (int b_i, int s_i)
{ return hash_table[b_i].GetSlotKey(s_i); }

unsigned int GetCount(int b_i)
{ return hash_table[b_i].GetCount(); }
};

void CheckFile (fstream &DATAFILE);

void PrintData(HT &ht);

int main ()
{
fstream DATAFILE, SAVEFILE;
HT ht;

DATAFILE.open("DATAIN.txt", ios::in);
CheckFile(DATAFILE);

ht.InsertData(DATAFILE);
PrintData(ht);

SAVEFILE.open("SAVEFILE.dat", ios:ut | ios::binary);
CheckFile(SAVEFILE);

SAVEFILE.write(reinterpret_cast<char*>(&ht), sizeof(ht));

SAVEFILE.close();


SAVEFILE.open("SAVEFILE.dat", ios::in | ios::binary);
HT ht2;


SAVEFILE.seekg(0L, ios::end);
long int buffer = SAVEFILE.tellg();
SAVEFILE.seekg(0L, ios::beg);
SAVEFILE.read(reinterpret_cast<char*>(&ht2), buffer);

SAVEFILE.close();

PrintData(ht2);


return 0;
}

void CheckFile (fstream &FILE)
{
if (!FILE.is_open())
{
cout << "Unable to open FILE, the program will now shut down...";
exit(1);
}
}

void PrintData(HT &ht)
{
unsigned int i, j;
for (i = 0; i < MAXBUCKETS; i++)
{
cout << "\n\nBUCKET #" << i+1 << endl;
for (j = 0; j < ht.GetCount(i) ; j++)
{ cout << "SLOT #" << j+1 << " " << ht.GetKey(i,j)<< endl; }
for (j; j < MAXSLOTS; j++)
{ cout << "SLOT #" << j+1 << " " << "'EMPTY'"<< endl; }
}
}

int HT::Hash (string s)
{
int index, char_sum;

char_sum = s[1] + s[3] + s[5];
index = char_sum % (MAXBUCKETS-OVERFLOW);

return index;
}



void HT::InsertData (fstream &DATAFILE) //(fstream &DATAFILE, BUCKET *hash_table, int &collisions)
{

while (!DATAFILE.eof())
{
stored = false;
tempdata.clear();

getline(DATAFILE, tempdata);
cout << tempdata << "\n\n";
index = Hash(tempdata.substr(0,10));

while (!stored)
{
if (hash_table[index].GetCount() < MAXSLOTS)
{
SetSlot(index, hash_table[index].GetCount(), tempdata.substr(0,10), tempdata.substr(10));
hash_table[index].AddCount();
cout << endl << index << "\t";
cout << hash_table[index].GetCount() << endl << endl;

stored = true;
}
else if (hash_table[index].GetOverflow() != 0)
{
cout << "\n\noverflow" << index;
index = hash_table[index].GetOverflow();
}
else
{
cout << "\n\nnooverflow" << index << "\n\n";
for (int i = (MAXBUCKETS - OVERFLOW); i < MAXBUCKETS; i++)
{
if (hash_table[i].GetCount() < MAXSLOTS)
{
SetSlot(i, hash_table[i].GetCount(), tempdata.substr(0,10), tempdata.substr(10));

cout << hash_table[i].GetSlotKey(hash_table[i].GetCount());

hash_table[i].AddCount();


cout << endl << index << "\t";
cout << hash_table[index].GetCount() << endl << endl;
cout << endl << i << "\t";
cout << hash_table[i].GetCount() << endl << endl;

hash_table[index].SetOverflow(i);
stored = true;
if (i = MAXBUCKETS-1)
i=0;
break;
}
}
}
}
}

}