为什么这样把文本文件输出到编辑框不换行

feidegengao 2012-12-17 12:15:07

FILE *pFile = fopen("D:\\Users\\lihua\\Desktop\\li.txt", "r");
fseek(pFile, 0, SEEK_END);
int nlen = ftell(pFile);
rewind(pFile);

char *buf;
buf = new char[nlen+1];
fread(buf, 1, nlen, pFile);
buf[nlen] = '\0';

CString str(buf);
m_edit.SetWindowText(str);
fclose(pFile);

这样输出在编辑框并不换行,edit属性设置了multiline了,但是把fopen("D:\\Users\\lihua\\Desktop\\li.txt", "r");
设置为"rb"的话就会换行或者

CFile file(_T("D:\\Users\\lihua\\Desktop\\li.txt"), CFile::modeRead);
ULONGLONG ullLen = file.GetLength();
char *buf = new char[ullLen+1];
file.Read(buf, ullLen);
buf[ullLen] = '\0';
CString str(buf);
m_edit.SetWindowText(str);
file.Close();

也会换行
...全文
123 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
linxren 2012-12-17
  • 打赏
  • 举报
回复
你把用 "r"和"rb"两者读出来的数据看下就知道了。 我怀疑是"\r\n"变成"\n"了
feidegengao 2012-12-17
  • 打赏
  • 举报
回复
引用 1 楼 linxren 的回复:
你把用 "r"和"rb"两者读出来的数据看下就知道了。 我怀疑是"\r\n"变成"\n"了
确实是这样的,解决了

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧