title: Infile streaming in switch statements
body: <p>How do I randomize words from a txt file into a switch statement?</p>
  
  <p>I have these text files which have short words in each sentence, and I want to randomize each word that comes out of the file. Another issue, is that the switch statement doesn't return anything. What am I doing wrong?</p>
  
  <pre><code> 26 string grabword(char input)
   27 {
   28     string word;
   29     switch(input)
   30     {
   31         case 'A':
   32             {
   33             ifstream infile;
   34             infile.open("sample1.txt");
   35             infile &gt;&gt; word;
   36             return word;
   37             }
   38         case 'B':
   39             {
   40             ifstream infile;
   41             infile.open("sample2.txt");
   42             infile &gt;&gt; word;
   43             return word;
   44             }
   45         case 'C':
   46             {
   47             ifstream infile;
   48             infile.open("sample3.txt");
   49             infile &gt;&gt; word;
   50             return word;
   51             }
   52        return word;
   53 }
  </code></pre>
  
  <p>What I tried:</p>
  
  <p>removing break statements.</p>
  
  <p>returning actual string.</p>
  
  <p>the output is nothing.</p>