title: Reading data from file into an array
body: <p>The program output Should be:</p>
  
  <blockquote>
    <p>The numbers are: 101 102 103 104 105 106 107 108 108 110</p>
  </blockquote>
  
  <p>But my output is:</p>
  
  <blockquote>
    <p>The numbers are: 0 0 0 0 0 0 0 0 1606416272 32767</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>// This program reads data from a file into an array.
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt; // To use ifstream
  using namespace std;
  
  int main()
  {
      const int ARRAY_SIZE = 10; // Array size
      int numbers[ARRAY_SIZE];   // Array number with 10 elements
      int count = 0;             // Loop counter variable
      ifstream inputFile;        // Input file stream object
  
      // Open the file.
      inputFile.open("TenNumbers.rtf");
  
      // Read the numbers from the file into the array.
      while (count &lt; ARRAY_SIZE &amp;&amp; inputFile &gt;&gt; numbers[count]){
          count++;
      }
  
      // Close the file.
      inputFile.close();
  
      // Display the numbers read:
      cout &lt;&lt; "The numbers are: ";
      for (count = 0; count &lt; ARRAY_SIZE; count++){
          cout &lt;&lt; numbers[count] &lt;&lt; " ";
      }
  
      cout &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>This is the contents of the TenNumbers.rtf file I'm reading the data from:</p>
  
  <pre><code>101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  </code></pre>
  
  <p>UPDATE 1:
  I tried using txt file but the results are similar. </p>
  
  <blockquote>
    <p>The numbers are: 0 0 0 0 0 0 0 0 1573448712 32767</p>
  </blockquote>
  
  <p>UPDATE 2:
  I found where the issue was. After running <code>if (inputFile.good())</code> I found out the file was not getting opened.</p>