title: read data from text file c++
body: <p>I have the following code, where i have a text file stored in a folder(folder2)which is stored in another folder(folder1). My program shows the name of the contents stored in folder2 which is the text file,but I would to be able to read the contents of the text file line by line.How can I do this??
  Here is my code:</p>
  
  <pre><code>#include &lt;dirent.h&gt; // directory header
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt; // exit()
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main()
  {
      DIR *pdir = NULL; 
      pdir = opendir ("C:\\folder1\\folder2");
      struct dirent *pent = NULL;
  
      if (pdir == NULL) 
      {
          cout &lt;&lt; "\nERROR! pdir could not be initialised correctly";
          exit (3);
      } // end if
  
      while (pent = readdir (pdir)) 
      {
          if (pent == NULL) 
          {
             cout &lt;&lt; "\nERROR! pent could not be initialised correctly";
              exit (3);
          }
          cout &lt;&lt; pent-&gt;d_name &lt;&lt; endl;
      }
      closedir (pdir);
      cin.get ();
      return EXIT_SUCCESS;
  }
  </code></pre>