title: How to read same file twice in a row
body: <p>I read through a file once to find the number of lines it contains then read through it again so I can store some data of each line in an array. Is there a better way to read through the file twice than closing and opening it again? Here is what I got but am afraid it's inefficient.</p>
  
  <pre><code>int numOfMappings = 0;
  ifstream settingsFile("settings.txt");
  string setting;
  while(getline(settingsFile, setting))
  {
      numOfMappings++;
  }
  char* mapping = new char[numOfMappings];
  settingsFile.close();
  cout &lt;&lt; "numOfMappings: " &lt;&lt; numOfMappings &lt;&lt; endl;
  settingsFile.open("settings.txt");
  while(getline(settingsFile, setting))
  {
      cout &lt;&lt; "line: " &lt;&lt; setting &lt;&lt; endl;
  }
  </code></pre>