title: C++ - List files of directory and save output result on txt
body: <p>I need to output the result of this code to a txt. When I try it saves only one line.</p>
  <pre><code>
  using namespace std;
  std::string c;
  
  void list_dir(const char *path) {
  struct dirent *entry;
  DIR *dir = opendir(path);
  if (dir == NULL) {
     return;
  }
  while ((entry = readdir(dir)) != NULL) {
  c = entry-&gt;d_name;
  cout &lt;&lt; c &lt;&lt; endl;
  }
  closedir(dir);
  }
  
  </code></pre>
  <p>Thanks</p>