如何通过CFile的函数向文件写入一个double型的数据(这个数据是一个double的变量)? 我知道的是将double型转换为Cstring类,然后再写入,但我不知怎么转换,请朋友们帮帮忙!!!
解决方案 »
- 利用log4cxx写日志问题
- 授权认证编程中的一些问题
- 2008QQ界面代码分享,有图
- VC 拦截OPENPROCESS函数问题
- 极度郁闷,求助C++中关于指针的问题
- 用CToolBar的SetImageList,图标就是现实不出来。
- CTreeCtrl不显示条目的问题!谢谢大家!
- 在用webbrowser时,在窗口中显示网页时,当窗口改变大小时,怎么改变网页大小??
- 有两个对话框(A,B),当我点击主对话框(A)时,操作不起作用;点击对话框(B)时操作才起作用,应该怎么办?
- 在VC中每次insert ActiveX时,总搜索office2000,不知是什么原因
- 关于程序自启动的路径问题
- 真没想到,时隔四年,还能够用上80C51知识
wsprintf(szBuffer,"%f",dblValue);
double d=1.02365;
s.format(_T("%f"),d);另,发错板块了!
至于你还要通过CFile写入到文件中,那你就自己写几行代码,先调用CFile的Open函数打开文件,然后再调用CFile的Write函数,将刚才华仔转换后的字符串写入到文件中,然后再调用CFile的Close函数关闭文件即可。
double num=12.34;
mystr.Format("%f",num);
如果是的,我给你写几句:
CFile hFile;
double fValue = 3.1415926;
CString strFilePath = _T("C:\\Test.txt");
if (!hFile.Open(strFilePath, CFile::modeWrite|CFile::modeCreate))
{
printf("Create File Failed, FileName = %s\n", strFilePath);
}
else
{
CString strValue = _T("");
strValue.Format("%f", dValue);
hFile.Write(strValue, strValue.GetLenth());
} hFile.Close();
_stprintf_s(szBuffer,_T("%f"),dblValue);
CString strValue = _T("");
strValue.Format("%f", dValue);
hFile.Write(strValue, strValue.GetLenth());
问题基本解决,但这个_T是什么意思? 还有几是怎么控制 浮点数的小数点位数,按照你这样输出默认的6位,
请说一下。。
CString strText(_T(""));
double num = 12.3456789;
strText.Format(_T("%lf"), num);
try
{
CStdioFile file;
file.Open(_T("F:\\11.txt"), CFile::modeCreate|CFile::modeWrite);
file.WriteString(strText);
file.Close();
}
catch (CFileException* e)
{
e->ReportError();
e->Delete();
}