Wt examples 4.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.h>
8#include <Wt/WStringUtil.h>
9
10#include "Dictionary.h"
11#include <fstream>
12#include <iostream>
13#include <time.h>
14#include <stdlib.h>
15
16std::wstring RandomWord(Dictionary dictionary)
17{
18 std::ifstream dict;
19 if (dictionary == DICT_NL) {
20 dict.open((WApplication::appRoot() + "dict-nl.txt").c_str());
21 } else { // english is default
22 dict.open((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 widen(retval);
47}
std::wstring RandomWord(Dictionary dictionary)
Definition: Dictionary.C:16
Dictionary
Definition: Dictionary.h:15
@ DICT_NL
Definition: Dictionary.h:17

Generated on Fri May 6 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.3