Just like the topic heading sounds, whenever I debug my code, my iterator is a "<Bad Ptr>". This only happens in the method where I am trying to write my HashTable to a file. In every other method the iterator works fine. Anyone know what's up?
Here is the method with the problem. The iterator in the for loop is the problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void HashTable::logFile(){
string fileName;
ofstream myfile;
list<string>::iterator it;
cout<<"Please enter file name: ";
cin >> fileName;//gets file name
myfile.open(fileName.c_str(), ios::out | ios::trunc);
//cout<<myfile.is_open()<<endl;//shows if file opened or not
int bucket = 0;
for(it = l[bucket].begin(); it!=l[bucket].end(); it++){
myfile<<" Bucket: "<<bucket<<" "<<endl;
for(int j = 0; j < l[bucket].size(); j++){
myfile<<"Name: " <<j + 1<<" "<<*it<<"\r\n";//print info
}
bucket++;
}
myfile.close();//close the file
}
In case you need it, here is the h file for my hash table.
On first iteration everything is fine, then you are comparing iterators from two different containers. Not to mention that there is serious loghic problem here.