| Wt examples
    3.3.0
    | 
#include <string>Go to the source code of this file.
| Enumerations | |
| enum | Dictionary { DICT_EN = 0, DICT_NL = 1 } | 
| Functions | |
| std::wstring | RandomWord (Dictionary dictionary) | 
| enum Dictionary | 
Definition at line 13 of file Dictionary.h.
| 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);
}
 1.7.5.1
 1.7.5.1