65,187
社区成员




SYSTEMTIME systime;
GetLocalTime(&systime); //得到当前时间
CString str = NULL;
str.Format("E:\\%4d-%02d-%02d %02d-%02d-%02d.txt", systime.wYear,systime.wMonth,systime.wDay, systime.wHour,systime.wMinute,systime.wSecond);
CString m_time = str;
//创建一个文本文件
CStdioFile file;
file.Open( m_time, CFile::modeCreate|CFile::modeWrite);
string strContent = "121323"; //想要写在这个文本文件中的内容
char sendbuf[1024] = {0};
strcpy(sendbuf, strContent.c_str());
file.Write(sendbuf, 1024);
file.Close();
//获取当前时间的例子
#include <stdio.h>
#include <time.h>
void main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "\007The current date/time is: %s", asctime (timeinfo) );
exit(0);
}
HANDLE CreateFile(
LPCTSTR lpFileName, // pointer to name of the file
DWORD dwDesiredAccess, // access (read-write) mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// pointer to security attributes
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to file with attributes to
// copy
);