Wt examples
3.2.1
|
00001 /* 00002 * Copyright (C) 2011 Emweb bvba, Heverlee, Belgium 00003 * 00004 * See the LICENSE file for terms of use. 00005 */ 00006 00007 #include <Wt/WApplication> 00008 #include <Wt/WStringUtil> 00009 00010 #include "Dictionary.h" 00011 #include <fstream> 00012 #include <iostream> 00013 #include <time.h> 00014 #include <stdlib.h> 00015 00016 std::wstring RandomWord(Dictionary dictionary) 00017 { 00018 std::ifstream dict; 00019 if (dictionary == DICT_NL) { 00020 dict.open((Wt::WApplication::appRoot() + "dict-nl.txt").c_str()); 00021 } else { // english is default 00022 dict.open((Wt::WApplication::appRoot() + "dict.txt").c_str()); 00023 } 00024 00025 std::string retval; 00026 int numwords = 0; 00027 while(dict) { 00028 getline(dict, retval); 00029 numwords++; 00030 } 00031 dict.clear(); 00032 dict.seekg(0); 00033 00034 srand(time(0)); 00035 int selection = rand() % numwords; // not entirely uniform, but who cares? 00036 00037 while(selection--) { 00038 getline(dict, retval); 00039 } 00040 getline(dict, retval); 00041 for(unsigned int i = 0; i < retval.size(); ++i) 00042 if(retval[i] < 'A' || retval[i] > 'Z') 00043 std::cout << "word " << retval 00044 << " contains illegal data at pos " << i << std::endl; 00045 00046 return Wt::widen(retval); 00047 }