title: Why are the words from the text file displayed in the program in alphabetical order instead of the order of how the text files put it?
body: <p>So, I have the work mostly done here, but I can't seem to figure out how to have the words in the order of how the text files displays it. It just takes the words from the text files, and puts the words in alphabetical order. Text Files are at the bottom of this page.</p>
  <p>Text File Analysis</p>
  <p>Write a program that reads the contents of two text files and compares them in the following ways:</p>
  <p>•   It should display a list of all the unique words contained in both files.
  •   It should display a list of the words that appears in both files.
  •   It should display a list of the words that appears in the first file, but not the second.
  •   It should display a list of the words that appears in the second file, but not the first.
  •   It should display a list of the words that appears in either the first or second file, but not in both.</p>
  <p>Hint: Use set operations to perform these analyses. Also, see Chapter 10 for a discussion of string tokenizing.</p>
  <p>This is what I have so far:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;set&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  using namespace std;
  
  void displaySet(set&lt;string&gt;);
  void displayDifference(set&lt;string&gt;, set&lt;string&gt;);
  
  int main()
  {
      ifstream inputFile;
      string name;
      const int MIN_VALUE = 1;
      const int MAX_VALUE = 2;
      int numbers;
      unsigned seed = time(0);
      
      srand(seed);
      
      set&lt;string&gt; firstFileWords;
      set&lt;string&gt; secondFileWords;
      
      inputFile.open(&quot;firstTextFile.txt&quot;);
      cout &lt;&lt; &quot;Reading data from the first file.\n&quot;;
      
      cout &lt;&lt; endl;
      
      while (inputFile &gt;&gt; name)
      {
          firstFileWords.insert(name);
      }
      
      displaySet(firstFileWords);
      
      inputFile.close();
      
      inputFile.open(&quot;secondTextFile.txt&quot;);
      
      cout &lt;&lt; endl;
      
      cout &lt;&lt; &quot;Reading data from the second file.\n&quot;;
      
      while (inputFile &gt;&gt; name)
      {
          secondFileWords.insert(name);
      }
      
      cout &lt;&lt; endl;
      
      displaySet(secondFileWords);
      
      cout &lt;&lt; endl;
      
      cout &lt;&lt; &quot;The differences between the two files:\n&quot;;
      
      cout &lt;&lt; endl;
      
      displayDifference(firstFileWords, secondFileWords);
      
      displayDifference(secondFileWords, firstFileWords);
      
      cout &lt;&lt; endl;
      
      numbers = rand() % 2 + 1;
      
      if(numbers = 2)
      {
          displaySet(secondFileWords);
          cout &lt;&lt; &quot;\nThe Second File Words&quot;;
      }
      else
      {
          displaySet(firstFileWords);
          cout &lt;&lt; &quot;\nThe First File Words&quot;;
      }
      return 0;
  }
  
  void displaySet(set&lt;string&gt; s)
  {
      for (auto element : s)
      {
          cout &lt;&lt; element &lt;&lt; &quot; &quot;;
          cout &lt;&lt; endl;
      }
  }
  
  void displayDifference(set&lt;string&gt; set1, set&lt;string&gt; set2)
  {
      vector&lt;string&gt; result(set1.size() + set2.size());
      
      auto iter = set_difference(set1.begin(), set1.end(),
                                 set2.begin(), set2.end(),
                                 result.begin());
                                 
      result.resize(iter - result.begin());
      
      for (auto element : result)
      {
          cout &lt;&lt; element &lt;&lt; &quot; &quot;;
      }
  }
  </code></pre>
  <p>These are the words from the text files I mentioned:</p>
  <p>//firstTextFile.txt</p>
  <p>It should display a list of all the unique words contained in both files.
  It should display a list of the words that appears in both files.
  It should display a list of the words that appears in the first file, but not the second.
  It should display a list of the words that appears in either the first or second file, but not in both.</p>
  <p>//secondTextFile.txt</p>
  <p>It should display a list of all the unique words contained in both files.
  It should display a list of the words that appears in both files.
  It should display a list of the words that appears in the second file, but not the first.
  It should display a list of the words that appears in either the first or second file, but not in both.</p>
  <p>The differences between them are the third sentences.</p>