Я пытаюсь добавить строку даты в начало моего имени файла, и я не могу понять, почему это не работает. У меня есть функция, которая захватывает дату и время и превращает их в строковый формат, затем у меня есть окно GetSaveFileName, чтобы пользователь мог сохранить файл в окне окна. когда я запускаю программу, она падает при сохранении файла. Кто-нибудь может увидеть, какую ошибку я допустил?
Заранее спасибо
// Set file name
void Set_FileName(HWND hWnd)
{
// This is the structure that creates the windows open/save dialogue system
OPENFILENAME ofn;
// This is the path and filename that the user will select/write
char file_name[100];
// Initial address set to zero?
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
// This is the parameter of the file name and location
ofn.lpstrFile = file_name;
// Set the initial file name
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 100;
// What file types the user can use
ofn.lpstrFilter = "Text Files\0*.TXT\0";
ofn.nFilterIndex = 1;
// Needs a particular linker library to work, libcomdlg32.a
GetSaveFileName(&ofn);
// Update what the current date and time is
Get_Date();
// Add a string to the start of the filename
sprintf(file_name, "%s" + (LPARAM)ofn.lpstrFile, s_Date);
// Update filename
ofn.lpstrFile = file_name;
}
Это функция даты. Здесь нет никаких ошибок, это просто для справки. Он обновляет глобальную строку с именем s_Date;
// Function to record the date and time as a string
void Get_Date()
{
// Grab the current time
time_t now = time(0);
// I have no idea what is happening here
tm *ltm = localtime(&now);
// Turn the date into a readable string format
stringstream ss_Date;
ss_Date << 1900 + ltm->tm_year << 1 + ltm->tm_mday << "_" << ltm->tm_hour << ltm->tm_min << "_" << endl;
ss_Date >> s_Date;
}