I have << overloaded to write to a file, however I get an error when I try to use it in main. I tried calling the actual write method. Is the SpareTable that operator that is failing. I already checked the .h and .cpp parameters and that all my #includes where in place. Thanks for the help
static ofstream lout ("lists.txt");
srand (2231);
SkipList list;
int i, compares;
try{
for (int n = 1; n <= 5; n++){
i = rand();
compares = list.add (i);
updateStats (n, 5, compares);
if (compares == -1) {
cout << "memory overflow!\n";
exit (1);
}
lout << "** add #" << setw(5) << n << ": " << setw(5) << i << " **\n"; //<< list; // this gives error
list.write(lout); // yet this works fine
void SkipList::write (ofstream& outfile)const {
SkipListNode* current = heads[0];
while (current != NULL){
current -> write (outfile);
current = current -> getNext(0);
}
outfile <<"\n";
}
ofstream& operator << (ofstream& outfile, const SkipList& list){
list.write(outfile);
return outfile;
}
void SkipListNode::write (ofstream& outfile) const{
outfile << value << " ";
for (int i = 0; i < getNumberOfLinks(); i++){
if (getNext(i)){
outfile << "( " << getNext(i) -> getValue() << ") ";
}
else {
outfile << "( / )";
}
}
outfile << endl;
}
ofstream& operator << (const SkipListNode& node, ofstream& outfile){
node.write(outfile);
return outfile;
}
/*******master.h*********/
#ifndef MASTER_H
#define MASTER_H
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ostream;
using std::ios;
#include <iomanip>
using std::setw;
using std::setprecision;
#include <fstream>
using std::ofstream;
#include <ctime>
#include <cstdlib>
#include <cmath>
#include "Node.h"
#include "LinkedNode.h"
#include "ArrayBoundsException.h"
#include "SkipListNode.h"
#include "SkipList.h"
#endif