You might want to use Boost Filesystem. A more DIY approach could look like this:
#include <string>
#include <vector>
#include <dirent.h>
#include <sys/types.h>
std::vector<std::string> readDirectory(std::string path)
{
std::vector<std::string> result;
auto dp = opendir(path.empty() ? "." : path.c_str()); // use current directory if path is empty
if(dp != nullptr)
{
while(true)
{
auto de = readdir(dp);
if(de == nullptr)
break; // all entries have been read, stop parsing
std::string entry(de->d_name);
result.push_back(entry);
}
closedir(dp);
}
return result;
}
Note that this approach will also put the current directory and the parent directory (paths "." and "..") into the vector. Also the entries might not be sorted in any way.