在MFC中,我想读取一个unicode编码的txt文件,一行一行的读取,然后把每行读出来的值放在string中。哪位哥们能给个实例啊?谢谢啦

解决方案 »

  1.   

    wstring strline;
    wfstream sk;
    sk.open(m_fName,fstream::in|fstream::out);
    while(getline(sk,strline))
    {
    string s = (char *)_bstr_t(strline.c_str() );
            }
    这样读出来放在s里,数据不对啊,是??:,而里面实际是:LOG啊
      

  2.   

    void CreadlogDlg::OnBnClickedButton1()
    {
    CStdioFile stdFile;
    if(!stdFile.Open(L"d:\\20100823.log", CFile::modeRead | CFile::typeBinary))
    {
    AfxMessageBox(L"打开文件错误");
    return;
    }
    CString strLine;
    while(stdFile.ReadString(strLine))
    {
    AfxMessageBox(strLine);
    }
    stdFile.Close();
    }
      

  3.   

    对于unicode编码的文件要读取必须以二进制的形式打开
      

  4.   

    CStdioFile stdFile;
    CString suu=L"C:\\32.log";
        if(!stdFile.Open(suu, CFile::modeRead | CFile::typeBinary))
        {
            MessageBox("打开文件错误");
            return;
        }
        CString strLine=L"";
        while(stdFile.ReadString(strLine))
        {
            AfxMessageBox(strLine);
        }
        stdFile.Close();我用的VC6.还是不行啊
      

  5.   


    try
    {
    CFile file;
    file.Open(_T("F:\\11.txt"), CFile::modeRead);
    DWORD len = file.GetLength();
    WCHAR* pBuf = new WCHAR[len+1];
    memset(pBuf, 0, sizeof(WCHAR)*(len+1));
    file.Seek(2, CFile::begin);
    file.Read(pBuf, len);
    file.Close(); AfxMessageBox(CString(pBuf)); delete[] pBuf;
    pBuf = NULL;
    }
    catch (CFileException* e)
    {
    e->ReportError();
    e->Delete();
    }
      

  6.   

    谢谢你们,尤其谢谢VisualEleven