曹耘豪的博客

C++基础

  1. std::string::c_str()
  2. dirent.d_type
std::string::c_str()

c_str()函数返回一个指向正规C字符串的指针, 内容与本string串相同,这是为了与c语言兼容,在c语言中没有string类型,故必须通过string类对象的成员函数c_str()把string 对象转换成c中的字符串样式。

dirent.d_type

unsigned char d_type

This is the type of the file, possibly unknown. The following constants are defined for its value:

1
2
3
4
5
6
7
8
9
10
DIR* dirp = opendir(path.c_str());
dirent* dp;
while ((dp = readdir(dirp)) != NULL) {
std::string subpath = dp->d_name; // 文件名
LOG(INFO) << "path " << path << " subpath: " << subpath;
if ((dp->d_type == DT_REG)) { // 文件类型

}
}
(void)closedir(dirp);
   /