wstring转char*

#include  
#include  
#include  


using namespace std;  


char* ws2s(const wstring& ws)  
{  
_bstr_t t = ws.c_str();   
char* pchar = (char*)t;   
string result = pchar;  
char* charTmp = new char;  
strcpy(charTmp,result.c_str());  
pchar = NULL;  
delete pchar;  
return charTmp;  
}  


void main()  
{  
wstring w = L"你好\n";  
char* s = ws2s(w);  
cout< system("pause");  

你可能感兴趣的:(wstring转char*)