title: Error opening existing directory using opendir in c++
body: <p>I am making use of opendir() as below to access a directory. </p>
  
  <pre><code>DIR *dp;
  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;
  }
  </code></pre>
  
  <p>However, I keep getting the error below, even though the directory exists.</p>
  
  <pre><code>Error(2) opening /path/to/folder/
  </code></pre>
  
  <p>I am able to get a list of file names when I do ls /path/to/folder</p>