我有个文本记录了一系列的数据,但中间有#注释,我该怎么读取?
比如有1000行有效数据,但中间插入了很多注释信息: 
    #点数
    1000
    123.45    2.545
    25.45486  235.214 
    #说明-------------------注释没有规律
    35.44      555.48该怎么识别#行呢,请大虾提示,谢谢!

解决方案 »

  1.   

    判断 char *buf;
     while( buf=='#')
    {
    //移动到换行字符结束
     if(buf=='\n')
    {}
    }
     这是个字符处理的函数。。可以自己写一个的。
      

  2.   

    写错了
     while( buf !='/0')
    {
    if (buf == '#')
    {
    //移动到换行字符结束
      while(buf !='\n')
       {      }
    }
    buf++;
    }
      

  3.   

    不好意思,我的意思好象没讲清楚: 我需要将数字输入读入数组中,不需要了解#行的注释内容.不过非常感谢smilehsh() 的解答,请继续关注!继续指点
      

  4.   

    CFile file;
    CString fName;
    DWORD dwCount;
    DWORD dwLength;
    CString fBuf;
    char c;fName = "D:\\text.txt"; //change it according to your file
    file.Open((LPCTSTR)fName,CFile::modeRead,NULL); //open file
    if(!file)
    {
    TRACE("Open Error!\n");
    exit(0);
    }
    dwLength = file.SeekToEnd(); //Get the file amount of byte
    file.SeekToBegin();//set file pointer to the first byte
    dwCount = 0;while(dwCount <= dwLength)
    {
    file.Read(&c,1);
    dwCount++;
    if('#' != c)
    fBuf += c;
    else
    while(1)
    {
    file.Read(&c,1);
    dwCount++;
    if(0x0D == c) //seek to end of re
    break;
    else
    {
    file.Read(&c,1);
    dwCount++
    }
    }
    }This code is just simpleness,and I don't debug it.
    If the re is chinese,I consider this code will be down.
    So I just give you some ideas.
    Best Regards
    Thank you!