char buffer[10];
好象buffer定义太少,定义10,只能读9个字符

解决方案 »

  1.   

    错在哪里
    是共享写错还是SEEK错,代码里没有相应的校验...
      

  2.   

    but you have not create File "c:\\hello.txt"
    before you open file use mode" CFile::modeReadWrite ¦ CFile::modeWrite"
    you must use " CFile::modeReadWrite ¦ CFile::modeCreate"
      

  3.   

    but you have not create File "c:\\hello.txt"
    before you open file use mode" CFile::modeReadWrite ¦ CFile::modeWrite"
    you must use " CFile::modeReadWrite|CFile::modeCreate"
      

  4.   

    you should only use CFile::modeReadWrite
    or use CFile::modeRead
    do not use them together!
    good luck
      

  5.   

    你应先创建文件:
    代码如下:
    CFile file;
        CFileException e;
        char* pFileName = "c:\\hello.txt";
        if(!file.Open(pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )//先创建文件再读写;
          {
        #ifdef _DEBUG
          afxDump << "File could not be opened " << e.m_cause << "\n";
        #endif
          }    file.Seek(10,CFile::begin);    char buffer[10];
        file.Read(buffer,10);
        
        MessageBox(buffer);
        file.Close();
      

  6.   

    hello cjia
    can not use CFile::modeRead CFile::modeReadWrite together?
    yes ! you can !
    you are wrong,but do that the same as CFile::modeReadWrite 
      

  7.   

    hello jxt100
    now  follow  you can not read data.
    before read you'd better  write something into  file
      

  8.   

    msdn:
    //example for CFile::Open
    CFile f;
    CFileException e;
    char* pFileName = "test.dat";
    if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )
       {
    #ifdef _DEBUG
       afxDump << "File could not be opened " << e.m_cause << "\n";
    #endif
       }
      

  9.   

    hello rationalMath(math)
    我刚写错了应该是:
    CFile::modeReadWrite 和CFile::modeWrite不可以同时用,会有Assertion Fail
    CFile::modeReadWrite 和CFile::modeRead 合用不会有错。
    我的意思 不 是 说 文件不能即读又写,只是上面的参数合用后程序运行会有错误。
    具体的原因我也不是很明白.
      

  10.   

    补充一下我用的是NT SEVER4 VC6
      

  11.   

    同意 rationalMath(math) 
    没有用CFile::modeCreate
      

  12.   

    hello  cjjia:原因为 
    modeRead =0x0000,  modeWrite = 0x0001, modeReadWrite = 0x0002;
    而MFC源吗:
    BOOL CFile::Open(LPCTSTR lpszFileName, UINT nOpenFlags,
    CFileException* pException)
    {

    switch (nOpenFlags & 3)
    {
    case modeRead:
    dwAccess = GENERIC_READ;
    break;
    case modeWrite:
    dwAccess = GENERIC_WRITE;
    break;
    case modeReadWrite:
    dwAccess = GENERIC_READ|GENERIC_WRITE;
    break;
    default:
    ASSERT(FALSE);  // !!!!此处会Assertion Fail
    }

    }
    you can now knowing
      

  13.   

    hello cjjia
    appendix:#define GENERIC_READ                     (0x80000000L)
    #define GENERIC_WRITE                    (0x40000000L)
      

  14.   

    hello cjjia 
    you can get code in
    "filecore.cpp"  location to    \\mfc\\src
      

  15.   

    hello cjjia
    thx 表示什吗?请告诉我
      

  16.   

    就是CFile::modeReadWrite 和CFile::modeWrite不可以同时用,
    改为CFile::modeRead 和CFile::modeWrite即可。
      

  17.   

    hello rationMath
    thx 就是 thanks bbs上常用的
      

  18.   

    hello cjjia :
       多谢! 交个朋友!如何!你在哪里工作!我在中关村
      

  19.   

    hello rationalMath(math)
        不用谢。我是一个学生,在浙大读书,如果不介意可以给我发email。
      

  20.   

    问题已经解决了,谢谢cjjia(),谢谢rationalmath(math),谢谢所有给出可能解决办法的人怎么给分呢?我现在不能给分 这样把,我再来发一个帖子,请你们进来,我给分,好不好?非常感谢