Last active
August 26, 2020 16:02
-
-
Save MRsoymilk/4c41bacb98ebb5ae1ed8c12a3d5dc7c6 to your computer and use it in GitHub Desktop.
C++ small tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // usage: | |
| // g++ -stdc++17 filelists.cpp -o filelists | |
| // ./filelists | |
| #include <iostream> | |
| #include <string> | |
| #include <filesystem> | |
| void _operation_(const std::string &msg){ | |
| std::cout << msg << std::endl; | |
| } | |
| void search(const std::string& path){ | |
| for(const auto& entry:std::filesystem::directory_iterator(path)){ | |
| entry.is_directory() ? search(entry.path()) : _operation_(entry.path()); | |
| } | |
| } | |
| void filelists(){ | |
| std::string path = "/tmp/role"; | |
| search(path); | |
| } | |
| int main(){ | |
| filelists(); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <random> | |
| int main(){ | |
| std::random_device dev; | |
| std::mt19937 rng(dev()); | |
| std::uniform_int_distribution<std::mt19937::result_type> dist(1, 10); | |
| for(int i=0;i<10;++i){ | |
| std::cout << dist(rng) << std::endl; | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <chrono> | |
| void time_elapsed() { | |
| std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<double>> start = std::chrono::system_clock::now(); | |
| // time run | |
| std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<double>> end = std::chrono::system_clock::now(); | |
| std::chrono::duration<double> elapsed_seconds = end - start; | |
| std::cout << "elapsed time: " << elapsed_seconds.count() << "s\n"; | |
| } | |
| int main(){ | |
| time_elapsed(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment