简体   繁体   中英

How do I hash strings in C++?

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?

With the standard libraries hash function :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM