forked from ChicoState/Wordler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.cpp
More file actions
30 lines (27 loc) · 758 Bytes
/
dictionary.cpp
File metadata and controls
30 lines (27 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "dictionary.h"
#include <vector>
#include <string>
#include <fstream>
// initiate word dictionary from file .wordler.data and store them as a
// list of upper case letters
dictionary::dictionary(){
std::ifstream read(".wordler.data");
if( !read.is_open() ){
words.push_back("words");
}
else{
std::string word;
while( getline(read,word) ){
//convert every word to UPPER CASE
for(int i=0; i<word.length(); i++){
word[i] = toupper(word[i]);
}
words.push_back(word);
}
}
read.close();
}
// select a random word from our dictionary and return it
std::string dictionary::select_word(){
return words.at(rand() % words.size());
}