Skip to content

Instantly share code, notes, and snippets.

@bhelyer
Created April 9, 2020 21:41
Show Gist options
  • Select an option

  • Save bhelyer/4bf7dfa26ecf5be3ae5662d823743349 to your computer and use it in GitHub Desktop.

Select an option

Save bhelyer/4bf7dfa26ecf5be3ae5662d823743349 to your computer and use it in GitHub Desktop.
#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