2015-12-05 13:47:36|?次阅读|上传:wustguangh【已有?条评论】发表评论
关键词:C/C++, 字符处理|来源:唯设编程网
字符串类型之间相互转换对于刚入门的C/C++程序员一定是一个巨大的考验,本文将常用字符串类型std::string,BSTR和CString之间的转换方法总结出来,供初学者参考:
CString strMfc=“test“; std::string strStl; #ifdef _UNICODE USES_CONVERSION strStl=W2A(strMfc.LockBuffer()); strMfc.UnlockBuffer(); #else strStl = strMfc.GetBuffer(0); strMfc.ReleaseBuffer(); #endif
CString strMfc; std::string strStl=“test“; strMfc=strStl.c_str();
BSTR bstrTest = ::SysAllocString(L”Test”); _bstr_t bstr_t(bstrTest); std::strStl = bstr_t; SysFreeString(bstrTest );
std::string name = "nisb"; _bstr_t bstr_t(name.c_str()); BSTR ret_val = bstr_t.GetBSTR();
关于这些数据类型的更多说明,可以参考http://vcsos.com/article/pageSource/120211/20120211075733.shtml