I am sorry if this is really basic but I just started and am extremely confused. I am trying to find the length of a string s using .length() I have included #include , #include "genlib.h"and #include "simpio.h", but am still getting an error.
#include <iostream>
#include "genlib.h"
#include "simpio.h"
#define MAX_HASH_CODE 10000
int Hash( int maxCode, string s);
#define Multiplier -1664117991L // Multiplier used in Hash function
int Hash(int maxCode, string s)
{
unsigned long hashcode = 0;
for (int i = 0; i < s.length(); i++)
hashcode = hashcode * Multiplier + s[i];
return (hashcode % maxCode);
}
int main ()
{
std::cout << "Please enter your name: ";
string name = GetLine();
int hashcode = Hash(MAX_HASH_CODE, name);
std::cout << " The hash code for your name is " << hashcode << "." <<std::endl;
return 0;
}
s.length() just gives an error and says:
request for member 'length' in 's', which is of non-class type 'string' {aka 'char*'}gcc