#include #include using namespace std; unsigned wordcount = 0; string *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 = new string[300000000]; while(!file_input.eof()){ file_input >> nextword; wordlist[wordcount] = nextword; wordcount++;; } cout << "Size of wordlist: " << sizeof(wordlist) << endl; cout << "Loaded " << wordcount << " 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(int i = 0; i < wordcount; i++) if(wordlist[i] == query) return true; return false; } void cleanup_word_list(){ delete[] wordlist; } 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; } cleanup_word_list(); return 0; }