你得到stdafx.h中,把“afx.h”包含进去。
然后再用CFile类的相关成员函数,如果你的文件是很规范的话,如要求一行一行读,那可以用它的继承类CStdioFile,它提供ReadString()和WriteString()的成员函数,这样就不用Write(buf,len)这些CFile的函数了。

解决方案 »

  1.   

    建立一个MFC支持的控制台应用程序就可以了。
      

  2.   

    // example for CStdioFile::ReadString
    extern CStdioFile f;
    char buf[100];f.ReadString( buf, 99 );
      

  3.   

    CFile myFile("myfile", CFile::modeCreate | CFile::modeReadWrite);
    CString str1="String1", str2="String2", str;// Create a storing archive.
    CArchive arStore(&myFile, CArchive::store);// Write str1 and str2 to the archive
    arStore.WriteString( str1 );
    arStore.WriteString( "\n" );
    arStore.WriteString( str2 );
    arStore.WriteString( "\n" );// Close the storing archive
    arStore.Close();// Create a loading archive.
    myFile.SeekToBegin();
    CArchive arLoad(&myFile, CArchive::load);// Verify the two strings are in the archive.
    arLoad.ReadString( str );
    ASSERT( str == str1 );
    arLoad.ReadString( str );
    ASSERT( str == str2 );
      

  4.   

    那你不会使用fread()读啊 ?我觉得这个很方便