1、CString to char*
1) pc = str.GetBuffer(str.GetLength() + 1);
Str.ReleaseBuffer();
2) pc = (SLPSTR)(LPCTSTR)str;
3) int nsttLength = str.GetLength() + 1;
pc = new char[nstrLength];
Strncpy(pc, (LPCTSTR)str, nstrLength);
2、char* to CString
Str.Format(“%s”, pc);
3、CString to string
s = str.GetBuffer();
str.ReleaseBuffer();
4、string to CString
str.Format(“%s”, s.c_str());
5、string to char*
pc = (char*)s.c_str(); //char*
pc = s.c_str(); //const char*
6、char* to string
1) string s(pc); //初始化时
2) s.assign(pc); //调用成员函数
浙公网安备 33010602011771号