-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict-eng.cpp
More file actions
34 lines (34 loc) · 745 Bytes
/
dict-eng.cpp
File metadata and controls
34 lines (34 loc) · 745 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
31
32
33
34
#include <stdexcept>
#include <cctype>
#include <iostream>
#include <fstream>
#include <set>
#include <string>
const std::set<std::string>& readDictWords(std::string filename)
{
static std::set<std::string> dict;
if(dict.size() == 0U)
{
size_t cnt = 0;
std::ifstream ifile(filename.c_str());
if(ifile.fail()){
throw std::logic_error("Cannot open dictionary file.");
}
std::string instr;
while(ifile >> instr)
{
if(isupper(instr[0])) continue;
bool onlyLetters = true;
for(char c : instr){
if(!isalpha(c)) onlyLetters = false;
}
if(onlyLetters){
dict.insert(instr);
cnt++;
}
}
ifile.close();
std::cerr << "Read " << cnt << " words into dictionary." << std::endl;
}
return dict;
}