Время модификации linux c ++

0

Я пытаюсь получить дату последней модификации файлов папки в C++. Но я не понимаю, как я могу заменить "afile.txt", но имя переменной.

Когда я заменяю "afile.txt" чем-то другим, у меня есть эта ошибка:

proj.cpp: В функции 'Folder getdir2 (std :: string, std :: vector> &, std :: string, std :: string, std :: string): proj.cpp: 325: 25: error: can not convert 'const string {aka const std :: basic_string} в' const char * для аргумента '1 to' int stat (const char *, stat *) stat (t1, & attrib); // получить атрибуты файла 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
  • 0
    Это то, что ссылки для.
Теги:
time

1 ответ

1

Похоже, вы пытаетесь передать std::string в stat. stat является C-функцией и как таковой принимает только const char * (строка "C").

Используйте метод .c_str() для std::string чтобы получить строку C:

std::string filename;
...
stat(filename.c_str(), &attrib);

Ещё вопросы

Сообщество Overcoder
Наверх
Меню