【发布时间】:2016-01-31 16:21:42
【问题描述】:
我正在尝试编写一个聊天程序。
由于我的问题不大,所以请大家帮忙。
当我尝试发送CString 格式化字符串时,它只接收字符串的第一个字母。
我将CAsyncSocket 用于套接字。
我用char* 格式字符串试了一下,效果很好。
各位大佬能告诉我怎么回事吗?
我的代码如下:
工作。
char* buf = new char[m_strMsg.GetLength()];
buf = "helloworld!";
m_ClientSocket.Send("sended", m_strMsg.GetLength());
m_ClientSocket.Send(buf, 10);
没用。
CString a = _T("helloworld!");
m_ClientSocket.Send(a,10);
我也试过了:
CString a = _T("helloworld!");
char* buf = new char[a.GetLength()];
buf = (LPSTR)(LPCTSTR)a;
m_ClientSocket.Send(buf,a.GetLength()];
【问题讨论】: