使用LPCTSTR类型转换后即可将CString类的字符串转为char*.
MSDN中的相关说明如下:
CString objects also have the following characteristics:
- CString objects can grow as a result of concatenation operations.
- CString objects follow “value semantics.” Think of a CString object as an actual string, not as a pointer to a string.
- You can freely substitute CString objects for const char* and LPCTSTR function arguments.
- A conversion operator gives direct access to the string’s characters as a read-only array of characters (a C-style string).
Tip Where possible, allocate CString objects on the frame rather than on the heap. This saves memory and simplifies parameter passing.
具体实现如下:
aa= (LPSTR)(LPCTSTR)bb;
另外还有一种方法:
aa=bb.GetBuffer(bb.GetLenth());