网上百度了一番,关于CString转为char *,众说纷纭,我用的VS2015,能编译过去的只有下面一种写法:
CString str = "ABCDEF";
char *pBuf = (char *)str.GetBuffer(0);
但是我按上面的方法只能得到首个字节,即输出pBuf只能得到A(不知道为什么,难道是因为我没刷新缓冲区?)
后来手动遍历了一下CString,改成了这样:
CString str = "ABCDEF";
char s[10];
int len = str.GetLength();
for(int i = 0; i < len; i++) {
s[i] = str.getAt(i);
} s[len] = '\0';
这样的话全英文字符可以,但是中文会丢失信息。各位大佬给指点一下。。
已解决:
参考自 http://blog.csdn.net/linrulei...