我这里有比较全的各种字符类之间的转换
AnsiString -> char * AnsiString.c_str();
char * -> AnsiString AnsiString=AnsiString(char);
BSTR -> char* char* char1=AnsiString(bstr).c_str();
wchar_t -> ansistring ansistring(wchar_t)
ansistring -> wchart ansistirng.WideChar();
char -> WideString char *s="中华人民共和国";
wchar *p=Widetring(s).BSTR();
WideString -> char wchar_t *p=L"中华人民共和国";
char *s=AnsiString(p).c_str();
要借助于AnsiString与WideString互换;
char * c -> wchar_t * cc AnsiString con = c;
cc = con.WideChar( cc , con.WideCharBufSize );
wchar_t * c -> char * cc AnsiString con = c;
cc = con.c_str();
WideString -> wchar_t WideString a = L"abc";
wchar_t *b = new wchar_t[4];
wcscpy(b, a); //c运行库unicode字符串拷贝函数
AnsiString=AnsiString(b);
Pointer -> char; typedef void* Pointer;
Pointer pTemp;
直接可以用AnsiString的c_str() 返回字串的char* 指针
假如需要保存下来可以这样
AnsiString s = "abcde";
char * buf = new char[s.Length()+1];
memset(buf,s.Length()+1);
strcpy(buf,s.c_str();
//.... 使用buf
delete [] buf; buf = NULL;
AnsiString My_AnsiString="abcd";
char *MyChar;
MyChar=My_AnsiString.c_str();
来晚了:(
AnsiString str = "ABCDEF";
Char *char = str.c_str();
这样可以了
AnsiString.c_str();