1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| // collate::hash example #include <iostream> // std::cin, std::cout #include <string> // std::string, std::getline #include <locale> // std::locale, std::collate, std::use_facet int main () { std::string myberry = "strawberry"; std::string yourberry; std::locale loc; // the "C" locale const std::collate<char>& coll = std::use_facet<std::collate<char> >(loc); long myhash = coll.hash(myberry.data(),myberry.data()+myberry.length()); std::cout << "Please, enter your favorite berry: "; std::getline (std::cin,yourberry); long yourhash = coll.hash(yourberry.data(),yourberry.data()+yourberry.length()); if (myhash == yourhash) std::cout << "Mine too!\n"; else std::cout << "I prefer strawberries...\n"; return 0; }
|