Wt examples  3.2.1
Functions
Dictionary.C File Reference
#include <Wt/WApplication>
#include <Wt/WStringUtil>
#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

std::wstring RandomWord ( Dictionary  dictionary)

Definition at line 16 of file Dictionary.C.

{
std::ifstream dict;
if (dictionary == DICT_NL) {
dict.open((Wt::WApplication::appRoot() + "dict-nl.txt").c_str());
} else { // english is default
dict.open((Wt::WApplication::appRoot() + "dict.txt").c_str());
}
std::string retval;
int numwords = 0;
while(dict) {
getline(dict, retval);
numwords++;
}
dict.clear();
dict.seekg(0);
srand(time(0));
int selection = rand() % numwords; // not entirely uniform, but who cares?
while(selection--) {
getline(dict, retval);
}
getline(dict, retval);
for(unsigned int i = 0; i < retval.size(); ++i)
if(retval[i] < 'A' || retval[i] > 'Z')
std::cout << "word " << retval
<< " contains illegal data at pos " << i << std::endl;
return Wt::widen(retval);
}

Generated on Sun May 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1