C++基础
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:
DT_UNKNOWNThe type is unknown. Only some filesystems have full support to return the type of the file, others might always return this value. 类型未知。少数文件系统会出现此函数不支持的文件类型,另一些则总是返回这个值。译者注:总之这个值是为了应对不兼容的文件系统而设置的。DT_REGA regular file. 常规文件DT_DIRA directory. 目录DT_FIFOA named pipe, or FIFO. See FIFO Special Files. 一个命名管道,或FIFO。DT_SOCKA local-domain socket. 套接字DT_CHRA character device. 字符设备DT_BLKA block device. 块设备DT_LNKA symbolic link. 符号链接
1 | DIR* dirp = opendir(path.c_str()); |
using 的3种使用
- 用于 namespace:using namespace std;
- 用于子类引用父类
- 类型别名(C++)
可读性:
1 | // 1 |
模板别名:
1 | // 正确 |