CStdioFile的ReadString是以行为单位的,读取的String中不包含回车换行,需要自己添加“\r\n”。

解决方案 »

  1.   

    见这段MSDN说明:
    Text mode provides special processing for carriage return–linefeed pairs. When you write a newline character (0x0A) to a text-mode CStdioFile object, the byte pair (0x0A, 0x0D) is sent to the file. When you read, the byte pair (0x0A, 0x0D) is translated to a single 0x0A byte.即是:
    在读的模式下,把换行和回车转换为单个'\r'回车,所以你显示不出来换行。
    解决:
    CString strAll;
    CFile file("d:\\text.txt",CFile::modeRead | CFile::typeText);
    char BUF[10000];
    UINT length=file.Read(BUF,10000);
    strAll.Format("%s",BUF);
    this->SetWindowText(strAll);