时间修改linux c++
Time modification linux c++
我正试图获得c++中文件夹文件的最后修改日期。但是我不明白我怎么能代替" file.txt"而是一个变量名。
当我用其他东西替换" file.txt"时,我得到了这个错误:
project .cpp: In function ' Folder getdir2(std::string)Std::string, Std::string;Std::string) ': project .cpp:325:25:错误:不能转换' const string{也称为const std::basic_string} '到' const char* '为参数' 1 '"int stat(const char*, stat*)"stat (t1,及鲜明);//获取文件属性
代码如下:
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
您似乎正在尝试将std::string
传递给stat
。stat
是一个C函数,因此只接受const char *
(一个"C"字符串)作为输入。
使用std::string
的.c_str()
方法获取C字符串:
std::string filename;
...
stat(filename.c_str(), &attrib);
相关文章:
- 在C++/Linux中设置单调时钟的一些技巧
- Linux的Cpp上的计时器
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 在Linux中哪里可以找到互斥、未来等的源代码
- 如何在linux终端中同时编译和运行c++代码
- 在Linux for Windows上编译C++代码时出错
- 如何找到锁定Linux futex的C++行
- 在linux上调试巨大的C++项目
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- c++方法参数只能在linux的发布模式下自行更改
- 在Linux和C++中的Windows上,散列字符串值会产生不同的输出
- 这里在 Linux 中具有"CreatePipe"和"CreateProcessW"功能吗?
- 函数在Windows或Linux上运行时表现不同
- 在Linux下捕获SIGKILL的C++程序
- 在为LINUX创建共享库时,如何避免STL的私有/弱副本
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 如何在CPP中创建应该在Windows和Linux上运行的套接字?
- mysql C++ connector [mysql-connector-c++-8.0.19-linux-glibc2
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- CMake WxWidgets项目成功地在Linux上构建,但没有在Windows上构建