C++ Builder : string->char* wstring->char*

string->char*  和 wstring->char*

方法一:

(1)将wstring.c_str()转为wchar_t*

方法二:

(1)将string.c_str(), wstring.c_str()转为AnsiString(http://blog.csdn.net/bannico/article/details/7577728),

(2)将AnsiString.c_str()转为char*

复制代码

方法一:
string temp;
const char* nodename = temp.c_str();
方法二:
struct IPAddress{
    std::wstring hostname;
    std::vector ips;
};

scripting::IPAddress dns = (*pPreloadDns)[i];
AnsiString strA = dns.hostname.c_str();
char * hn = strA.c_str();

复制代码

但据说这样很不可靠(http://bbs.csdn.net/topics/30479944),安全的做法是:

方法三:
String str="123456";
int len=str.Length();
char *cp=new char[len+1];
StrPCopy(cp, str);

你可能感兴趣的:(C++ Builder : string->char* wstring->char*)