怎么读取文本文件的多行,以两个或多个换行结束。谢谢

解决方案 »

  1.   

    采用CStdioFile,每次可以读一行:CStdioFile file;
    file.open(...);
    CString str;
    while( file.ReadString( str ) )
    {
       .....
    }
      

  2.   

    CString m_disp,m_end;
    m_end = _T("\n\n");//两个换行符
    myfile.Open("XX.txt",CFile::modeRead);//从XX.txt中读入数据
    myfile.SeekToBegin();
    myfile.Read(m_disp.GetBufferSetLength(myfile.GetLength()),myfile.GetLength());
    if (!m_disp.IsEmpty())
    {
    int index = m_disp.Find(m_end);
    m_disp = m_disp.Right(m_disp.GetLength()-index-4);
             }


    UpdateData(false);
     
    myfile.Close();该程序可以读任意行中英文字符,直到遇到"\n\n"停止
      

  3.   

    下面一个程序是读入150个HTML文件,然后为每个文件加上两个链接。
    读取HTML文件和读取TXT文件一样的。
    下面程序可用作读取整个文档。只需稍微改动一下。
    至于以两个或多个换行结束
    str += "\r\n";
    执行两次或多次。
    int count = 0;
    CString head, end, inshead, insend;
    head.Format("E:\\0\\download\\luolan\\new\\jjl\\jjl\\jjl");
    end.Format(".htm");
    insend += "</p><p align=\"center\"><a href=\"../%C6%DA%BF%AF%D4%D3%D6%BE.htm\">回目录</a></p>";
    inshead += "<p align=\"center\"><a href=\"../%C6%DA%BF%AF%D4%D3%D6%BE.htm\">回目录</a></p><p>";
    for(int i = 10; i < 28; i++)
    {
    CFile myfile;
    CString index, txt, filename = head;
    index.Format("%d", i);
    filename += index;
    filename += end; myfile.Open(filename, CFile::modeReadWrite);
    DWORD file_size = myfile.GetLength();
    myfile.Read(txt.GetBuffer(file_size), file_size);
    txt.ReleaseBuffer();
    int Init1 = txt.Find("<body>");
    txt.Insert(Init1+6, inshead);
    int Init2 = txt.Find("</body>");
    txt.Insert(Init2+7, insend);
    int file_len = txt.GetLength();
    myfile.Seek(0, CFile::begin);
    myfile.Write(txt.GetBuffer(file_len), file_len);
    myfile.Close();
    }
    MessageBox("OK");
      

  4.   

    楼上的zhude同志,你的成员变量怎么记的这么熟悉?还是等用的时候现查MSDN?真是让人羡慕啊:)