Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:34:16+00:00 2026-06-12T01:34:16+00:00

CString output ; const WCHAR* wc = LHellow World ; if( wc != NULL

  • 0
CString output ;
const WCHAR* wc = L"Hellow World" ;
if( wc != NULL )
{   
     output.Append(wc);
}
printf( "output: %s\n",output.GetBuffer(0) );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:34:17+00:00Added an answer on June 12, 2026 at 1:34 am

    you can also try this:

    #include <comdef.h>  // you will need this
    const WCHAR* wc = L"Hello World" ;
    _bstr_t b(wc);
    const char* c = b;
    printf("Output: %s\n", c);
    

    _bstr_t implements following conversion operators, which I find quite handy:

    operator const wchar_t*( ) const throw( ); 
    operator wchar_t*( ) const throw( ); 
    operator const char*( ) const; 
    operator char*( ) const;
    

    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_t instance 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::GetBuffer returns LPTSTR (i.e. TCHAR*) and not LPCTSTR (i.e. const TCHAR*).

    Another option is to use conversion macros:

    USES_CONVERSION;
    const WCHAR* wc = L"Hello World" ;
    const char* c = W2A(wc);
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to convert CString to const char*, i used that const char* cstr
Possible Duplicates: Is String.Format as efficient as StringBuilder C# String output: format or concat?
I need to convert CString to BYTE array. I don't know why, but everything
So I have a CString which contains a number value e.g. 45.05 and I
I am new to Cstring, sorry for asking dumb question, please help. char string[10];
I have a code in which Cstring and wchar_t both are used. I think
If I have code such as class CString { int GetLength(); }; bool smaller(CString
I am trying to convert an int to a cstring. I've decided to read
How can I find the position of the end of a CString? I am
#include <cstring> int main() { char *pName = new char[10]; char dummy[] = dummy;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.