CString output ;
const WCHAR* wc = L"Hellow World" ;
if( wc != NULL )
{
output.Append(wc);
}
printf( "output: %s\n",output.GetBuffer(0) );
CString output ; const WCHAR* wc = LHellow World ; if( wc != NULL
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
you can also try this:
_bstr_timplements following conversion operators, which I find quite handy:EDIT: clarification with regard to answer comments: line
const char* c = b;results in a narrow character copy of the string being created and managed by the_bstr_tinstance which will release it once when it is destroyed. The operator just returns a pointer to this copy. Therefore, there is no need to copy this string. Besides, in the question,CString::GetBufferreturnsLPTSTR(i.e.TCHAR*) and notLPCTSTR(i.e.const TCHAR*).Another option is to use conversion macros:
The problem with this approach is that the memory for converted string is allocated on stack, so the length of the string is limited. However, this family of conversion macros allow you to select the code page which is to be used for the conversion, which is often needed if wide string contains non-ANSI characters.