std::string之间的转化

BSTR和std::string之间的转化
#include <comdef.h>

// this is the BSTR
BSTR Bstr = ::SysAllocString(L"Hello World"); 

// covert to std::string
_bstr_t bstr_t(Bstr);
std::string str(bstr_t);


// free the BSTR
::SysFreeString(Bstr);
std::string name = "hello";
_bstr_t bstr_t(name.c_str());//取name的字符串形式
   BSTR ret_val = bstr_t.GetBSTR(); //得到BSTR

你可能感兴趣的:(std::string之间的转化)