// shows a string is similar to a container #include #include #include #include #include int main() { bool reject = false; std::string firstword; std::string secondword; try { std::cout << "Input a first word and press enter: " << '\n'; std::cin >> firstword; for (size_t index(0); index != firstword.size(); ++index) { if (isalpha(firstword[index])) continue; else reject = true; } if (reject) throw std::exception(); std::cout << "Input a second word and press enter: " << '\n'; std::cin >> secondword; for (size_t index(0); index != secondword.size(); ++index) { if (isalpha(secondword[index])) continue; else reject = true; } if (reject) throw std::exception(); std::sort(firstword.begin(), firstword.end()); std::sort(secondword.begin(), secondword.end()); if (firstword == secondword) std::cout << "Anagram \n"; else std::cout << "Not anagram \n"; } catch (...) { std::cerr << "***An exception was thrown***\n"; } }