Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CString to wstring

Posted on 2007-11-26
5
Medium Priority
?
4,487 Views
Last Modified: 2013-12-03
Hi,
I need to convert a CString to a wstring. Actual I do it while initialize the wstring (std::wstring path(sTempBuffer);) , but now I need to do it in a function. So how to convert a CString to a allway initialized wstring?

Ingo
0
Comment
Question by:Ocrana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20353155
have a look to this great article:
http://www.codeproject.com/string/cppstringguide2.asp
0
 

Author Comment

by:Ocrana
ID: 20353333
sorry cannot see the cstring to wstring, only wstring to cstring.
0
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 20353467
If you have UNICODE set, just use

CString test;
wstring wstr = (LPCTSTR) test;
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20353487
there is a wstring constructor that accepts 'const char *'
CString is equivalent to LPCTSTR, which is the same as 'const char *'

so, you should be able to use

CString a = "test"';
std::wstring st(a);
 
0
 
LVL 86

Expert Comment

by:jkr
ID: 20353495
On, and if it is an ANSI CString, make that

#include <ios>
using namespace std;

CString test;
string tmp = (LPCTSTR) test;
wstring wstr = widen(tmp.begin(),tmp.end());
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question