From 79f2ec2b85ab3841c041b068e5d6f03029fd4e4f Mon Sep 17 00:00:00 2001 From: Sasza Stanczew Date: Thu, 25 Apr 2024 15:52:13 +0200 Subject: [PATCH] =?UTF-8?q?AdvC++=20-=20daty=20zmian=20na=20wektorach,=20a?= =?UTF-8?q?le=20pobieramy=20daty=20zmian=20na=20pocz=C4=85tku?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/exercises/files/main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AdvancedCppV2/Presentation/exercises/files/main.cpp b/AdvancedCppV2/Presentation/exercises/files/main.cpp index 66f041d..bf795f4 100644 --- a/AdvancedCppV2/Presentation/exercises/files/main.cpp +++ b/AdvancedCppV2/Presentation/exercises/files/main.cpp @@ -58,17 +58,17 @@ int main() { std::cout << "File write time is " << std::asctime(std::localtime(&time)); }; - std::vector paths; + std::vector> paths; for (const auto& entry : fs::directory_iterator(fs::current_path().string() + "/project")) { if (fs::is_regular_file(entry.path())) { - paths.push_back(entry.path()); + paths.push_back(std::make_pair(entry.path(), fs::last_write_time(entry.path()))); } } - std::sort(paths.begin(), paths.end(), [](fs::path a, fs::path b) {return fs::last_write_time(a) > fs::last_write_time(b);}); + std::sort(paths.begin(), paths.end(), [](auto a, auto b) {return ( a > b );}); - std::cout << "Last modified file is: " << paths.front() << '\n'; - print_last_write_time(std::filesystem::last_write_time(paths.front())); - std::cout << "files which were longest unmodified: " << paths.back() << std::endl; - print_last_write_time(std::filesystem::last_write_time(paths.back())); + std::cout << "Last modified file is: " << paths.front().first << '\n'; + print_last_write_time(std::filesystem::last_write_time(paths.front().first)); + std::cout << "files which were longest unmodified: " << paths.back().first << std::endl; + print_last_write_time(std::filesystem::last_write_time(paths.back().first)); }