文件输入输出问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 04:13:00
我用的是vs2008,
想把几个float型的数据,float a,b,c;写到文件 abc.dat 中,然后再读出到float d,e,f

要求用mfc的CFile类写,

/////code////

float a,b,c;
a=1.1;
b=2.2345;
c=0.0067;
CFile f;
CFileException e;
TCHAR* pszFileName = _T("abc.dat");
if(!f.Open(pszFileName, CFile::modeCreate | CFile::modeWrite, &e))
{
TRACE(_T("File could not be opened %d\n"), e.m_cause);
}

///下面不会写了,求助。。。。。
我想要的是可执行的代码,我也知道是用f.write和f.read,

谢谢 2楼和3楼的,3楼的代码是正确的,但是用记事本打开是乱码。。
http://zhidao.baidu.com/question/66851046.html

//将a, b, c写到abc.dat中
    float a,b,c;
    a=1.1;
    b=2.2345;
    c=0.0067;
    CFile f;
    CFileException e;
    TCHAR* pszFileName = _T("abc.dat");

    if (!f.Open(pszFileName, CFile::modeCreate | CFile::modeWrite, &e))
    {
        TRACE(_T("File could not be opened %d\n"), e.m_cause);
    }
    else
    {
        f.Write(&a, sizeof(float));
        f.Write(&b, sizeof(float));
        f.Write(&c, sizeof(float));
        f