title: List all text files in directory in C++
body: <p>I am trying to store the name of all txt files in a directory in a string and print them out. I need to count the number of txt files in the directory and then print the names. The part of counting is working, but I can't seem to get the name working. I have found some examples but they don't work in visual studio which is what I'm using.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>int main() {
  
      bool x = true;
      int i = 0;
  
      wchar_t* file = L"../Menu/Circuitos/*.txt";
      WIN32_FIND_DATA FindFileData;
  
      HANDLE hFind;
  
      hFind = FindFirstFile(file, &amp;FindFileData);
  
      if (hFind != INVALID_HANDLE_VALUE) {
  
          i++;
  
          while ((x = FindNextFile(hFind, &amp;FindFileData)) == TRUE) {
              i++;
          }
      }
  
      cout &lt;&lt; "number of files " &lt;&lt; i &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>