How can I convert from CString
to std::wstring
?
Asked
Active
Viewed 3.9k times
17

Mateen Ulhaq
- 24,552
- 19
- 101
- 135

subbu
- 3,229
- 13
- 49
- 70
-
2Please see this: http://stackoverflow.com/questions/258050/how-to-convert-cstring-and-stdstring-stdwstring-to-each-other – codaddict Jan 11 '10 at 10:48
-
1and http://stackoverflow.com/questions/859304/convert-cstring-to-const-char – Idan K Jan 11 '10 at 10:52
4 Answers
1
This should work as CString
has operator LPCTSTR()
defined:
CString s;
std::wstring s1 = s;

Mateen Ulhaq
- 24,552
- 19
- 101
- 135

Naveen
- 74,600
- 47
- 176
- 233
1
Try this:
std::wstring strString((LPCTSTR)strCString);

Mateen Ulhaq
- 24,552
- 19
- 101
- 135

Ashish
- 8,441
- 12
- 55
- 92
-
5Why use a C cast for that? A fellow-worker of mine once was in the position that he had to find explicit casts, as some of them didn't work on the platform he needed to port a 4MLoC project to. He praised everyone who used C++' explicit casts (you can grep for them) and fought hard to ban all C-style casts, since they were so hard to find. – sbi Jan 11 '10 at 11:10