VS2010 CString末尾加回车换行

来源:互联网 发布:apt模型与capm模型知乎 编辑:程序博客网 时间:2024/05/22 06:40

之前的代码是

CString str;//str+="\r\n";str+=(wchcar_t)"\r\n";str+=(char)"\r\n";

都不行,乱码。

后来改为:

CString str;str=str+(char)0x0d;str=str+(char)0x0a;  

 下面部分是网上摘抄:

在CString中不能直接访问指定位置的字符,所有要GetBuffer获得字符串指针,然后在字符串末尾添加回车、换行字符(回车的ASCII码是13,换行的ASCII码是10);

  例子代码:

  CString strTemp;
  LPTSTR pStr;

  int nLen=strTemp.GetLength();
  pStr=strTemp.GetBuffer(nLen+2);
  pStr[nLen]=13;
  pStr[nLen+1]=10;
  strTemp.ReleaseBuffer();  


0 0
原创粉丝点击