title: C++ How to search files in a directory with certain name?
body: <p>I want to find files that start with certain words. For example <code>abc</code>, <code>abc22424</code>, <code>abc44646</code>, <code>abc353535</code>.</p>
  
  <p>I found this on another question as starting point. Please help me, I am new to C++.</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;dirent.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int getdir (string dir, vector&lt;string&gt; &amp;files)
  {
      DIR *dp;
      struct dirent *dirp;
  
      if((dp = opendir(dir.c_str())) == NULL)
      {
        cout &lt;&lt; "Error(" &lt;&lt; errno &lt;&lt; ") opening " &lt;&lt; dir &lt;&lt; endl;
        return errno;
      }
      while ((dirp = readdir(dp)) != NULL)
        files.push_back(string(dirp-&gt;d_name));
      closedir(dp);
      return 0;
  }
  
  int main()
  {
      string dir = string("C:\\test");
      vector&lt;string&gt; files = vector&lt;string&gt;();
  
      getdir(dir,files);
      for (unsigned int i = 0;i &lt; files.size();i++)
        cout &lt;&lt; files[i] &lt;&lt; endl;
      return 0;
  }
  </code></pre>