Wt examples  3.7.1
Enumerations | Functions
Dictionary.h File Reference
#include <string>

Go to the source code of this file.

Enumerations

enum  Dictionary { DICT_EN = 0, DICT_NL = 1 }
 

Functions

std::wstring RandomWord (Dictionary dictionary)
 

Enumeration Type Documentation

◆ Dictionary

enum Dictionary
Enumerator
DICT_EN 
DICT_NL 

Definition at line 13 of file Dictionary.h.

13  {
14  DICT_EN = 0,
15  DICT_NL = 1
16 };

Function Documentation

◆ RandomWord()

std::wstring RandomWord ( Dictionary  dictionary)

Definition at line 16 of file Dictionary.C.

17 {
18  std::ifstream dict;
19  if (dictionary == DICT_NL) {
20  dict.open((Wt::WApplication::appRoot() + "dict-nl.txt").c_str());
21  } else { // english is default
22  dict.open((Wt::WApplication::appRoot() + "dict.txt").c_str());
23  }
24 
25  std::string retval;
26  int numwords = 0;
27  while(dict) {
28  getline(dict, retval);
29  numwords++;
30  }
31  dict.clear();
32  dict.seekg(0);
33 
34  srand(time(0));
35  int selection = rand() % numwords; // not entirely uniform, but who cares?
36 
37  while(selection--) {
38  getline(dict, retval);
39  }
40  getline(dict, retval);
41  for(unsigned int i = 0; i < retval.size(); ++i)
42  if(retval[i] < 'A' || retval[i] > 'Z')
43  std::cout << "word " << retval
44  << " contains illegal data at pos " << i << std::endl;
45 
46  return Wt::widen(retval);
47 }
static std::string appRoot()

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13