I have this code which should create & open a file.
OpenFile():
std::string fileName = GetCurrentDate() +".txt";
std::cout << fileName << std::endl; //debug
m_file.open(fileName);
if (!m_file.is_open()) {
LOG(0, "ERROR creating log file");
}
The log file's name should be the current date. (If I use a hardcoded text like "log.txt" it works.)
GetCurrentDate():
struct tm newtime;
__time32_t aclock;
_time32(&aclock);
_localtime32_s(&newtime, &aclock);
char buffer[32];
errno_t errNum;
errNum = asctime_s(buffer, 32, &newtime);
if (errNum) {
printf("Error code: %d", (int)errNum);
}
std::string str = buffer;
//buffer ends with an end line
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
return str;
The result fileName string is this: Tue Dec 27 03:29:17 2016.txt
Why doesn't it open the file?
(extra: isn't there a simpler way of getting current date? Y-M-D is enough for me)
(I use Visual Studio which recommended this)