_T的作用
_T和_TEXT是一样的,一般情况_T("Kurt")和“Kurt"没有什么区别。但对于UNICODE,一般加上_T.
如果想编译UNICODE版本的软件,则加上_T可以由编译器自动把字符串转换为Unicode的。
 
char* str,或unsigned char* str转换成CString

1。直接用构造函数。 
CString( LPCTSTR lpch, int nLength ); 
CString( const unsigned char* psz );

例:char ch[] = _T("this is a sample."); 
      CString str(ch); //or CString str = ch;

2用Format函数

例: char* test="asfdasfd"; 
     CString str; 
     str.Format("%s", test);

3强制转换

   (CString)char强制转换  

CString 转换为char *

LPTSTR 和char *意思同

1使用强制转换

例如:
CString theString( "This is a test" );
LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString;

2使用CString::GetBuffer

CString s(_T("This is a test "));
LPTSTR p = s.GetBuffer();
// 在这里添加使用p的代码
if(p != NULL) *p = _T('\0');
s.ReleaseBuffer(); 
// 使用完后及时释放,以便能使用其它的CString成员函数

posted on 2012-02-16 11:56  知识天地  阅读(2597)  评论(0编辑  收藏  举报