【发布时间】:2014-06-16 22:25:01
【问题描述】:
我正在尝试获取 C++ 中文件夹文件的最后修改日期。 但我不明白如何替换“afile.txt”而是一个变量名。
当我用其他东西替换“afile.txt”时,我得到了这个错误:
proj.cpp: 在函数'Folder getdir2(std::string, 标准::向量>&,标准::字符串,标准::字符串, std::string)': proj.cpp:325:25: 错误: 无法转换'const string {aka const std::basic_string}’ 到 ‘const char*’ 用于参数 ‘1’ 到‘int stat(const char*, stat*)’ 统计(t1,&属性); // 获取 afile.txt 的属性
代码如下:
struct tm* clock; // create a time structure
struct stat attrib; // create a file attribute structure
stat("afile.txt", &attrib); // get the attributes of afile.txt
clock = gmtime(&(attrib.st_mtime)); // Get the last modified time and put it into the time structure
【问题讨论】:
-
这就是references 的用途。