Solved

CString to wstring

Posted on 2007-11-26
5
4,258 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
  • 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 250 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

821 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