CString st=_T("123");
int nLength = st.GetLength();
int nBytes = WideCharToMultiByte(CP_ACP,0,st,nLength,NULL,0,NULL,NULL);
char* path1 = new char[ nBytes + 1];
memset(path1,0,nLength + 1);
WideCharToMultiByte(CP_OEMCP, 0, st, nLength, path1, nBytes, NULL, NULL);
path1[nBytes] = 0;
你用这个吧,有点麻烦,但是char*传化cstring 直接初始化就可以了
我试了楼上的方法也可以
CString st=_T("123");
char* p=(char*)st.LockBuffer();
st.Format(L"%s sdjf",p);
GetDlgItem(IDC_EDIT1)->SetWindowText(st);
一个函数搞定
CString 是取决于你工程使用的是什么字节类型它就是什么类型的.
如果你使用的是非宽字节,则CString::GetBuffer() 是 const char * 类型的
如果你使用的是宽字节,则CString::GetBuffer() 是 const wchar_t* 类型的 这时你要用WideCharToMultiByte进行转换。
希望有帮助。
直接赋值即可,内部已经重载了转换符
但要用 const char* ,
CString s="abc";
const char* p=s;
.LockBuffer
sprintf