How to convert a string to a PWCHAR

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ycinar
    New Member
    • Oct 2007
    • 39

    How to convert a string to a PWCHAR

    How can I convert a string (or a wstring) to a PWCHAR?
    Code:
    PWCHAR temp;
    
    wstring wstr;
    
    // Basically I want to do 
    // temp = wstr
    // but casting didnt work
    // temp = PWCHAR (wstr) 
    //  error C2440: 'type cast' : cannot convert from 'std::wstring' to 'PWCHAR'
    Any help?

    thanks
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You cannot convert a wstring to a PWCHAR unless you allocate an array the sizeof the wstring and copy the wstring to it.

    However, you can use the c_str() method fo wstring to expose the string as a const WCHAR. In this case you would:

    [code=cpp]
    wstring wstr;
    PCWCH temp = wstr.c_str();
    [/code]

    Comment

    Working...