Wt examples  3.7.1
Dictionary.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Emweb bv, Herent, Belgium
3  *
4  * See the LICENSE file for terms of use.
5  */
6 
7 #include <Wt/WApplication>
8 #include <Wt/WStringUtil>
9 
10 #include "Dictionary.h"
11 #include <fstream>
12 #include <iostream>
13 #include <time.h>
14 #include <stdlib.h>
15 
16 std::wstring RandomWord(Dictionary dictionary)
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 }
Dictionary
Definition: Dictionary.h:13
std::wstring RandomWord(Dictionary dictionary)
Definition: Dictionary.C:16
static std::string appRoot()

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