// collect words from keyboard until 'END' is typed. #include #include #include #include #include #include int main() { std::string const end_input("END"); std::vector words; std::string aword; bool reject = false; try{ while(aword != end_input) { std::cout << "Please input a word. (input END to end input). \n"; std::cin >> aword; for(int index(0); index < aword.length() && not reject; index++) { if(isalpha(aword[index])) continue; else reject = true; } if(reject) throw std::exception(); words.push_back(aword); } std::cout << "These are your words in alphabetical order.\n"; std::sort(words.begin(), words.end()); for(int i(0); i != words.size(); ++i) { std::cout << words[i] << '\n'; } } catch(...) { std::cerr << "***An exception was thrown ***\n"; } }