Wt examples 4.8.0
Functions
Dictionary.C File Reference
#include <Wt/WApplication.h>
#include <Wt/WStringUtil.h>
#include "Dictionary.h"
#include <fstream>
#include <iostream>
#include <time.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

std::wstring RandomWord (Dictionary dictionary)
 

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((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}
@ DICT_NL
Definition: Dictionary.h:17

Generated on Mon Jul 11 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.4