CString t;
char buf[1024]={0};
t.Format(_T("%s"),_T("Hello"));
// TODO: Add your control notification handler code here
if(m_CSocke.Create())
{
//MessageBox(0,0,0);
m_CSocke.Connect(_T("pop.163.com"),110);
m_CSocke.Send(t,t.GetLength()+1);
m_CSocke.Receive((void *)buf,1024);
t.Format(_T("%s"),buf);
MessageBox(t,0,0); //here 显示出来的是乱码
//我用cmd telnet 连接上去,返回是 +OK Welcome to coremail Mail Pop3 Server (163coms[a0654ba7f7f5aa9d955bab4e305f6a
d7s])
}
else
{
t.Format(_T("%d"),GetLastError());
MessageBoxW(t,0,0);
}
m_CSocke.Close();
char buf[1024]={0};
t.Format(_T("%s"),_T("Hello"));
// TODO: Add your control notification handler code here
if(m_CSocke.Create())
{
//MessageBox(0,0,0);
m_CSocke.Connect(_T("pop.163.com"),110);
m_CSocke.Send(t,t.GetLength()+1);
m_CSocke.Receive((void *)buf,1024);
t.Format(_T("%s"),buf);
MessageBox(t,0,0); //here 显示出来的是乱码
//我用cmd telnet 连接上去,返回是 +OK Welcome to coremail Mail Pop3 Server (163coms[a0654ba7f7f5aa9d955bab4e305f6a
d7s])
}
else
{
t.Format(_T("%d"),GetLastError());
MessageBoxW(t,0,0);
}
m_CSocke.Close();
是Unicode程序
我把 t.Format(_T("%s"),buf); 改成 %x
然后显示出来的是 12f088
楼上两位方法都试了,还是不行,返回一样的现象 %s 是乱码 %x 是12f088
然后借用了他的代码,就ok了http://topic.csdn.net/u/20090819/09/8f16b5f2-bed0-4149-9035-8c99018dea81.html?seed=1635444852&r=59214561#r_59214561
下面这个functionint Cxxx::ustr_astr(char *ansistr ,WCHAR *unicodestr)
{
int result = 0;
int needlen = MultiByteToWideChar( CP_ACP, 0, ansistr, -1, NULL, 0);
if( needlen < 0 )
{
return needlen;
}
result = MultiByteToWideChar( CP_ACP, 0, ansistr, -1, unicodestr, needlen + 1);
if( result < 0 )
{
return result;
}
return strlen(ansistr);
}