How do I hash strings in C++?

113 Views Asked by At

I'm currently learning about hash table. Hashing integers are easy, but my assignment is to hash strings. I have given strings:

25674316-6058714                
56105665-7450612                
96917015-1417157                
48189873-3313151    

I have to hash them to fit into array of buckets[4]. How do I hash strings?

1

There are 1 best solutions below

0
Matthias247 On BEST ANSWER

With the standard libraries hash function:

std::string stringToHash = "25674316-6058714";
size_t result = std::hash<std::string>()(stringToHash);