468,512 Members | 1,508 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

How to convert a string to a PWCHAR

39
How can I convert a string (or a wstring) to a PWCHAR?
Expand|Select|Wrap|Line Numbers
  1. PWCHAR temp;
  2.  
  3. wstring wstr;
  4.  
  5. // Basically I want to do 
  6. // temp = wstr
  7. // but casting didnt work
  8. // temp = PWCHAR (wstr) 
  9. //  error C2440: 'type cast' : cannot convert from 'std::wstring' to 'PWCHAR'
Any help?

thanks
Jan 22 '08 #1
1 6561
weaknessforcats
9,207 Expert Mod 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. wstring wstr;
  2. PCWCH temp = wstr.c_str();
  3.  
Jan 22 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Convert TextBox.Text to Int32 Problem | last post: by
6 posts views Thread by centrino | last post: by
5 posts views Thread by B Vidyadhar Joshi | last post: by
7 posts views Thread by patang | last post: by
6 posts views Thread by patang | last post: by
4 posts views Thread by tshad | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.