i am trying to load the morsecode.txt into my tree struct but when i compile it i keep getting this errors
error C2440: '=' : cannot convert from 'decode *' to 'int *'|
error C2664: 'bintree<dataType>::insert' : cannot convert parameter 1 from 'int' to 'const decode &'|
error C2676: binary '[' : 'bintree<dataType>' does not define this operator or a conversion to a type acceptable to the predefined operator|
error C2228: left of '.printDecode' must have class/struct/union|
#include <iostream> // Standard C++ Screen I/O
#include <fstream> // Standard C++ File I/O
#include <iomanip>
#include <string>
#include <vector>
#include "bintree.h"
using namespace std;
/*
struct decode {
/* decode struct to contain morse code data
*/
string alphabet;
string code;
public:
decode() {
alphabet = "";
code = "";
}
decode(const decode &other) :
alphabet(other.alphabet),
code(other.code)
{
// copy constructor
}
void setDecode(const string &name, int num) {
alphabet = name;
code = num;
}
const string& getAlphabet() const {
return alphabet;
}
void printDecode(){
cout <<fixed<<setprecision(2);
cout <<setw(20)<<left<<alphabet<<setw(4)<<code<<"\n";
}
bool operator == (const decode &rhs) const
{
return (alphabet == rhs.alphabet);
}
bool operator > (const decode &rhs) const
{
return (alphabet> rhs.alphabet);
}
bool operator < (const decode &rhs) const
{
return (alphabet < rhs.alphabet);
}
void loadDecode(ifstream &fin) {
fin >> alphabet;
fin >> code;
}
};
bool operator ==(const decode& lhs, const decode& rhs)
{
return (lhs.alphabet == rhs.alphabet);
}
void loadDecode(bintree<decode> &decodes);
//void printEncode( vector<encode> &encodes);
void printDecode( bintree<decode> &decodes);
int main(int argc, char *argv[])
{
// vector<encode> encodes;
bintree<decode> decodes;
// loadEncode(encodes);
loadDecode(decodes);
// printEncode(encodes);
printDecode(decodes);
return 0;
}
void loadDecode(bintree<decode> &decodes)
{
ifstream fin;
decode de;
int *prt;
fin.open("morsecodes.txt");
if (!fin) {
cout << "Unable to read from " <<
"\n";
exit(0);
}
while (!fin.eof()) {
de.loadDecode(fin);
prt = new decode(de);
decodes.insert(*prt); //refer to lab 8
}
fin.close();
}
void printDecode( bintree<decode> &decodes)
{
unsigned int i;
for (i=0; i<decodes.size(); i++) {
decodes[i].printDecode();
}
printf("\n");
}