title: how to get filenames from a folder and keep filenames order unchanged?
body: <p>I have got filenames from a folder and sent names into <code>vector&lt;string&gt;</code>, but when I printed the <code>vector&lt;string&gt;</code>, I found that the order was not the same order as files in the folder.
  My code is shown as follows:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  void searchFileInDirectroy( const string&amp; dir, vector&lt;string&gt;&amp; outList );
  
  void searchFileInDirectroy( const string&amp; dir, vector&lt;string&gt;&amp; outList )
  {
          WIN32_FIND_DATA findData;
          HANDLE hHandle;
          string filePathName;
          string fullPathName;
  
          filePathName = dir;
          filePathName += "\\*.*";
  
          hHandle = FindFirstFile( filePathName.c_str(), &amp;findData );
          if( INVALID_HANDLE_VALUE == hHandle )
          {
                  cout&lt;&lt;"Error"&lt;&lt;endl;
                  return ;
          }
  
          do
          {
                  if( strcmp(".", findData.cFileName) == 0 || strcmp("..", findData.cFileName) == 0 )
                  {
                          continue;
                  }
  
                  fullPathName = dir;
                  fullPathName += "\\";
                  fullPathName += findData.cFileName;
  
                  if( findData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY )
                  {
                          searchFileInDirectroy( fullPathName, outList );
                  }
                  else
                  {
                          outList.push_back(fullPathName);
                  }
  
          } while( FindNextFile( hHandle, &amp;findData ) );
  
          FindClose( hHandle );
  }
  
  int main()
  {
      ///get filenames from folder;
      vector&lt;string&gt; pathList;
      searchFileInDirectroy("D:/OpenCV/calculate laef area--cui.ver2.0/source", pathList);
  
      for(unsigned int i=0;i&lt;pathList.size();i++)
      {
          cout&lt;&lt;pathList[i]&lt;&lt;endl;
      }
  return 0;
  }
  </code></pre>
  
  <p>The result is like that:</p>
  
  <p><img src="https://i.stack.imgur.com/YLEkl.jpg" alt="result"></p>
  
  <p>What I really want is that the order is from 1 to 12.</p>