Skip to content

Instantly share code, notes, and snippets.

@SnowyPainter
Created January 24, 2022 14:51
Show Gist options
  • Save SnowyPainter/ce7008f9fe4f3caba5f0f2d206edfb7e to your computer and use it in GitHub Desktop.
Save SnowyPainter/ce7008f9fe4f3caba5f0f2d206edfb7e to your computer and use it in GitHub Desktop.
save errors to file
#pragma warning(disable:4996)
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <ctime>
class ErrorReport {
private:
std::ofstream file;
std::string getNowTime() {
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::stringstream ss;
ss << std::put_time(std::localtime(&now), "%Y-%m-%d %X");
return ss.str();
}
public:
ErrorReport(std::string filename) {
file.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
}
void Write(std::string text) {
file << getNowTime() << " : " << text;
}
void WriteLine(std::string text) {
Write(text + "\n");
}
void CloseReport() {
file.close();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment