Created
January 24, 2022 14:51
-
-
Save SnowyPainter/ce7008f9fe4f3caba5f0f2d206edfb7e to your computer and use it in GitHub Desktop.
save errors to file
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
#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