470,858 Members | 1,837 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How to convert a string to a PWCHAR

How can I convert a string (or a wstring) to a PWCHAR?
Expand|Select|Wrap|Line Numbers
  1. PWCHAR temp;
  3. wstring wstr;
  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?

Jan 22 '08 #1
1 7185
9,208 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();
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
By using this site, you agree to our Privacy Policy and Terms of Use.