/****************************************************************************** * This program prints the lyrics to Farmer in the Dell * using a map to store the data. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace std; static const unordered_map PEOPLE = { {L"farmer", L"wife"}, {L"wife", L"child"}, {L"child", L"nurse"}, {L"nurse", L"cow"}, {L"cow", L"dog"}, {L"dog", L"cat"}, {L"cat", L"mouse"}, {L"mouse", L"cheese"} }; int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); wstring person = L"farmer"; wcout << L"The famer in the dell" << endl; wcout << L"The famer in the dell" << endl; wcout << L"Hi-ho, the derry-o..." << endl; wcout << L"The famer in the dell" << endl; wcout << endl; while (person != L"cheese") { wstring const OTHER_PERSON = PEOPLE.at(person); wcout << L"The " << person << L" takes the " << OTHER_PERSON << endl; wcout << L"The " << person << L" takes the " << OTHER_PERSON << endl; wcout << L"Hi-ho, the derry-o..." << endl; wcout << L"The " << person << L" takes the " << OTHER_PERSON << endl; wcout << endl; person = OTHER_PERSON; } wcout << L"The cheese stands alone" << endl; wcout << L"The cheese stands alone" << endl; wcout << L"Hi-ho, the derry-o..." << endl; wcout << L"The cheese stands alone" << endl; return 0; }