如何在指定位置创建一个文本文件,并以当前时间命名?

rcbblgy 2009-02-10 10:54:40
RT
...全文
282 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangsiyuanoo 2009-02-10
  • 打赏
  • 举报
回复
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();
joneshong 2009-02-10
  • 打赏
  • 举报
回复
顶2楼,文件名取出系统时间做一个字符串就好了
yellowhwb 2009-02-10
  • 打赏
  • 举报
回复

//获取当前时间的例子
#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);
}
yellowhwb 2009-02-10
  • 打赏
  • 举报
回复
调用winapi

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
);

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧