<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Wt examples: /home/koen/project/wt/public-git/wt/examples/hangman/Dictionary.C File Reference</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">Wt examples  <span id="projectnumber">3.2.3</span> </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.5.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#func-members">Functions</a> </div> <div class="headertitle"> <div class="title">/home/koen/project/wt/public-git/wt/examples/hangman/Dictionary.C File Reference</div> </div> </div> <div class="contents"> <div class="textblock"><code>#include <Wt/WApplication></code><br/> <code>#include <Wt/WStringUtil></code><br/> <code>#include "<a class="el" href="Dictionary_8h_source.html">Dictionary.h</a>"</code><br/> <code>#include <fstream></code><br/> <code>#include <iostream></code><br/> <code>#include <time.h></code><br/> <code>#include <stdlib.h></code><br/> </div> <p><a href="Dictionary_8C_source.html">Go to the source code of this file.</a></p> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="func-members"></a> Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">std::wstring </td><td class="memItemRight" valign="bottom"><a class="el" href="Dictionary_8C.html#addb438135bbc4b68a5ff5b6c6dfa5dd4">RandomWord</a> (<a class="el" href="Dictionary_8h.html#a75d0a1670704923e348986686c3714f9">Dictionary</a> dictionary)</td></tr> </table> <hr/><h2>Function Documentation</h2> <a class="anchor" id="addb438135bbc4b68a5ff5b6c6dfa5dd4"></a><!-- doxytag: member="Dictionary.C::RandomWord" ref="addb438135bbc4b68a5ff5b6c6dfa5dd4" args="(Dictionary dictionary)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">std::wstring RandomWord </td> <td>(</td> <td class="paramtype"><a class="el" href="Dictionary_8h.html#a75d0a1670704923e348986686c3714f9">Dictionary</a> </td> <td class="paramname"><em>dictionary</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="Dictionary_8C_source.html#l00016">16</a> of file <a class="el" href="Dictionary_8C_source.html">Dictionary.C</a>.</p> <div class="fragment"><pre class="fragment">{ std::ifstream dict; <span class="keywordflow">if</span> (dictionary == <a class="code" href="Dictionary_8h.html#a75d0a1670704923e348986686c3714f9a7b7a0d1c13d5ae5a4e27e17b7b6e26c1">DICT_NL</a>) { dict.open((<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a88b082dadadd3fb7dbe10887e7d89c91">Wt::WApplication::appRoot</a>() + <span class="stringliteral">"dict-nl.txt"</span>).c_str()); } <span class="keywordflow">else</span> { <span class="comment">// english is default</span> dict.open((<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a88b082dadadd3fb7dbe10887e7d89c91">Wt::WApplication::appRoot</a>() + <span class="stringliteral">"dict.txt"</span>).c_str()); } std::string retval; <span class="keywordtype">int</span> numwords = 0; <span class="keywordflow">while</span>(dict) { getline(dict, retval); numwords++; } dict.clear(); dict.seekg(0); srand(time(0)); <span class="keywordtype">int</span> selection = rand() % numwords; <span class="comment">// not entirely uniform, but who cares?</span> <span class="keywordflow">while</span>(selection--) { getline(dict, retval); } getline(dict, retval); <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < retval.size(); ++i) <span class="keywordflow">if</span>(retval[i] < <span class="charliteral">'A'</span> || retval[i] > <span class="charliteral">'Z'</span>) std::cout << <span class="stringliteral">"word "</span> << retval << <span class="stringliteral">" contains illegal data at pos "</span> << i << std::endl; <span class="keywordflow">return</span> Wt::widen(retval); } </pre></div> </div> </div> </div> <hr size="1"><address style="text-align: right; margin: 3px"><small> Generated on Thu Nov 1 2012 for <a href="http://www.webtoolkit.eu/wt">the C++ Web Toolkit (Wt)</a> by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" border="0" style="vertical-align: middle; display: inline-block; height: 2em"></a> 1.7.5.1</small></address> </body> </html>