#include #include #include using namespace std; vector wordlist; void load_word_list(){ ifstream file_input; // If you run this example, change this to where words is for you file_input.open("/usr/share/dict/words"); string nextword; wordlist.reserve(200000); while(!file_input.eof()){ file_input >> nextword; wordlist.push_back(nextword); } cout << "Size of wordlist: " << sizeof(wordlist) << endl; cout << "Loaded " << wordlist.size() << " words\n"; cout << "Samples: " << wordlist[0] << " " << wordlist[1] << " " << wordlist[2] << endl; } // This'll work if we have wordlist and wordcount bool in_dictionary(string query){ // for each word in wordlist; // if that word is the same as the word in query // return true // return false for(string& cw : wordlist) if(cw == query) return true; return false; } int main(){ load_word_list(); string query; cin >> query; while(query.length()){ if(in_dictionary(query)) cout << "It's in the dictionary\n"; else cout << "It's not in the dictionary\n"; cin >> query; } return 0; }