jeudi 31 mars 2016

Unable to write date to file

I came across an idea where I wanted to log what my program is doing with date and time. So I wrote a small function, and upon compilation no error, and no runtime error except that it doesn't open log.txt and it won't even display the date.

#include <chrono>
#include <ctime>
#include <fstream>
#pragma warning(disable:4996)

void log(const char*& text)
{
    std::fstream fs;
    fs.open("log.txt", std::fstream::in | std::fstream::out | std::fstream::app);

    auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

    fs << ctime(&now) << text << std::endl;
}

int main()
{
    const char* log("Testin codenz stuff");
}

Aucun commentaire:

Enregistrer un commentaire