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

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 提示");
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

txwtech笛克特科

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值