VS2008多字符和Uincode模式下的通用字符转换

来源:互联网 发布:sip默认端口 编辑:程序博客网 时间:2024/06/15 22:28

CString cstr = "1234";

string  str = “5555”;

char *pCh = new  char[50];

strcpy(pCh,”world!”);

 

1CString char*

USES_CONVERSION;

pCh = T2A(cstr.GetBuffer());

cstr.ReleaseBuffer();

 

2char* CString

USES_CONVERSION;

cstr = A2T(pCh);

 

3string char*

strcpy(pCh,str.c_str());

 

4char* string

s.assign(ch);

 

5string CString

USES_CONVERSION;

cstr = A2T(const_cast<char*>(str.c_str()));

 

6CString string

USES_CONVERSION;

str.assign(T2A(cstr.GetBuffer()));

cstr.ReleaseBuffer();


7、CString → int

num = _ttoi(str);

 

8、string → int

num = atoi(str.c_str());