您当前的位置: 首页 >  c++

txwtech

暂无认证

  • 0浏览

    0关注

    813博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

vc++2015 CFile类以时间为文件名保存数据

txwtech 发布时间:2018-11-20 23:30:01 ,浏览量:0

vc++2015 CFile类以时间为文件名保存数据

void CCFile_testDlg::OnBnClickedBtnFwrite()
{
	// TODO: 在此添加控件通知处理程序代码
	char szCurrentDateTime[32];
	char szCurrentDateTime1[32];	
	CString path5,path6,path7;
	CTime nowtime;
	nowtime = CTime::GetCurrentTime();
	sprintf_s(szCurrentDateTime, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",  
		nowtime.GetYear(), nowtime.GetMonth(), nowtime.GetDay(),
		nowtime.GetHour(), nowtime.GetMinute(), nowtime.GetSecond());
	sprintf_s(szCurrentDateTime1, "%.4d-%.2d-%.2d",   //以年月日作为文件名保存数据。
		nowtime.GetYear(), nowtime.GetMonth(), nowtime.GetDay());	
	CString douhao = _T(",");
	CString hanzi = _T("自然");
	CString strEnter = _T("\r\n");//换行
	path5 = szCurrentDateTime; //日期时间
	path6 = szCurrentDateTime1;
	path7 = _T("d://txw//") + path6+_T(".txt"); //得到整体路径:d:/txw/2018-11-20
	//AfxMessageBox(path2);
	CFile file_1;
	file_1.Open(path7, CFile::modeNoTruncate | CFile::modeCreate | CFile::modeWrite);//打开文件
	file_1.SeekToEnd();//数据位置跳到文件末端
	//WORD unicode = 0xFEFF; //这句重要
	wchar_t unicode = 0xFEFF; //添加这个文件头,记事本打开才能识别里面的汉字,不会乱码。
	file_1.Write(&unicode, 2);
	file_1.Write(path5, wcslen(path5) * sizeof(wchar_t));//日期与时间
	file_1.Write(douhao, wcslen(douhao) * sizeof(wchar_t));//逗号
	file_1.Write(edit_wwid, wcslen(edit_wwid) * sizeof(wchar_t));//工号	 
	file_1.Write(douhao, wcslen(douhao) * sizeof(wchar_t));//逗号
	file_1.Write(hanzi, wcslen(hanzi) * sizeof(wchar_t));//汉字
	file_1.Write(douhao, wcslen(douhao) * sizeof(wchar_t));
	file_1.Write(edit_name, wcslen(edit_name) * sizeof(wchar_t));//英文名字
	file_1.Write(douhao, wcslen(douhao) * sizeof(wchar_t));
	file_1.Write(edit_sex, wcslen(edit_sex) * sizeof(wchar_t));//性别
	file_1.Write(strEnter, wcslen(strEnter) * sizeof(wchar_t));	//换行 
	file_1.Close();
	MessageBox(L"数据发送成功",L"cfile 提示");
}

 

关注
打赏
1665060526
查看更多评论
立即登录/注册

微信扫码登录

0.0400s