Created
April 9, 2020 21:41
-
-
Save bhelyer/4bf7dfa26ecf5be3ae5662d823743349 to your computer and use it in GitHub Desktop.
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 <chrono> | |
| #include <string> | |
| #include <fstream> | |
| #include <iomanip> | |
| #include <sstream> | |
| #include <iostream> | |
| #include <filesystem> | |
| using namespace std; | |
| using namespace chrono; | |
| using namespace filesystem; | |
| string getNewTime(); | |
| void overwriteFile(const string& path, const string& text); | |
| int main(int, char** argv) { | |
| const path loc{path{argv[0]}.parent_path() / "Alerm.txt"}; | |
| const string newTime{getNewTime()}; | |
| overwriteFile(loc.string(), newTime); | |
| return 0; | |
| } | |
| string getNewTime() { | |
| time_point nowt{system_clock::now()}; | |
| minutes m{30}; | |
| system_clock::duration d{m}; | |
| nowt += d; | |
| const time_t nowc{system_clock::to_time_t(nowt)}; | |
| stringstream ss; | |
| ss << put_time(localtime(&nowc), "%H:%M:%S"); | |
| return ss.str(); | |
| } | |
| void overwriteFile(const string& path, const string& text) { | |
| ofstream ofs{path, ios_base::out}; | |
| ofs << text << '\n'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment