CSting
输出: (1) https://blog.csdn.net/overlord_bingo/article/details/60140224 不含中文的情况下: CString s("hello world"); wcout << "s=" << s.GetString() << endl; wcout << "s=" << (LPCTSTR)s << endl;类型转换 含有中文的情况下需要添加: wcout.imbue(std::locale("chs")); 如下 CString s("hello world"); wcout.imbue(std::locale("chs")); wcout << "s=" << s.GetString() << endl; wcout << "s=" << (LPCTSTR)s << endl; (2)CString是unicode编码 CString a = "test"; printf("%sn",a);//输出t; ? 指针: ? 类型转换: (1)LPCTSTR是把CString类型的强制转换为常字符串 LPCTSTR相当于const char*;输出 :例如 CString str; 要用printf输出str printf("%s",(LPCTSTR)str); (2)CString 值赋给已分配内存的char *。 CString cstr1 = "ASDDSD";
int strLength = cstr1.GetLength() + 1;
char *pValue = new char[strLength];
strncpy(pValue,cstr1,strLength);
(3)char[]、char*、string转换成CString
c_str()和data()区别是:前者返回带‘/0‘的字符串,后者则返回不带‘/0‘的字符串. (4) CString转换成char[]、char*、string ? ? CString cstr =?" To?CString";? ? ? string? str=cstr.GetBuffer(0); ? 附注: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |