Wednesday, April 30, 2008

Convert CComBSTR to std::string

CComBSTR myString = _T("Hello");
std::wstring myWString(myString);

std::string str(myWString.begin(),myWString.end());
str.assign(myWString.begin(),myWString.end());

std::cout<< str.c_str();

Tuesday, April 29, 2008

Convert WString to String

std::string WString2String(const std::wstring& str)
{
std::string temp(str.length(), ' ');
std::copy(str.begin(), str.end(), temp.begin());
return temp;
}