title: Find *.txt files in directory c++
body: <p>I want to get txt files from directory with using c++. I searched in google and found "dirent.h" but I can't using this library. It gives me a C1083 fault. Here is my codes.I'm already included fstream,dirent.h vs...</p>
  
  <pre><code>ifstream fin;
  string dir, filepath;
  int num;
  DIR *dp;
  struct dirent *dirp;
  struct stat filestat;
  
  cout &lt;&lt; "dir to get files of: " &lt;&lt; flush;
  getline(cin, dir);  
  
  dp = opendir(dir.c_str());
  if (dp == NULL)
  {
      cout &lt;&lt; "Error(" &lt;&lt; errno &lt;&lt; ") opening " &lt;&lt; dir &lt;&lt; endl;
      return errno;
  }
  
  while ((dirp = readdir(dp)))
  {
      filepath = dir + "/" + dirp-&gt;d_name;
  
  
      if (stat(filepath.c_str(), &amp;filestat)) continue;
      if (S_ISDIR(filestat.st_mode))         continue;
  
  
      fin.open(filepath.c_str());
      if (fin &gt;&gt; num)
          cout &lt;&lt; filepath &lt;&lt; ": " &lt;&lt; num &lt;&lt; endl;
      fin.close();
  }
  </code></pre>
  
  <p>`</p>