Thanks, that fixed it.
*Note: i meant for .get to be .getline.
I've ran into another problem.
I have to store the persons name and the number of votes they have (the number of time their names appear in the input file) in the table. So, i thought i would create a struct to do this.
Code:
struct Candidate
{
string firstName;
int votes;
};
So, this would allow me to hash a candidate entry into the table, allowing me to store the name and the number of votes. So, i need to read a name in from the file, create a new Candidate (if one does not already exist), and set their name. Here is how i tried to do that:
Code:
Candidate array1[12];
//Read names in from file and hash them into table.
while(!inFile.eof())
{
inFile.getline(name, 20);
Candidate name;
name.firstName = name;
name.votes = 1;
array1[hash(name,12)] = name;
}
So, i create a new Candidate with:
Then, i try to set the name to the name read in from the file with:
Code:
name.firstName = name;
This gives me the first error.
Then i set the votes to 1. Then i try put the entry into the table with:
Code:
array1[hash(name,12)] = name;
This gives me the second error.
If i change the name of the Candidate to a random lettter/word like:
Code:
Candidate a;
a.firstName = name;
a.votes = 1;
array1[hash(name,12)] = a;
It will work. However, i believe it is just overwriting a everytime, so when i need to refer back to the entry to increase the number of votes, i won't be able to (i could be wrong here).
These are the errors i receive:
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Candidate' (or there is no acceptable conversion)
Error 2 error C2664: 'hash' : cannot convert parameter 1 from 'Candidate' to 'char *'
"That said, have you considered using std::tr1::unordered_set?"
I'm not sure what that is.
Thanks