Click here to Skip to main content
12,889,329 members (53,775 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 25 Oct 2011

C++: Converting an MFC CString to a std::string

, 30 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
In UNICODE:CString str = L"Test";std::wstring ws(str);std::string s;s.assign(ws.begin(), ws.end());

CString str = L"Test";
std::wstring ws(str);
std::string s;
s.assign(ws.begin(), ws.end());


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Architect Robotz Software
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionThis conversion is bad! Pin
Theo Buys1-Nov-13 5:29
memberTheo Buys1-Nov-13 5:29 
Questionconvert string to Cstring? Pin
Vijay Kumbhani29-Oct-13 3:05
groupVijay Kumbhani29-Oct-13 3:05 
AnswerRe: convert string to Cstring? Pin
steveb3-Nov-13 6:57
membersteveb3-Nov-13 6:57 
BugNot a unicode aware transformation Pin
pasztorpisti16-Aug-12 11:52
memberpasztorpisti16-Aug-12 11:52 
GeneralI don't think it would give the desired result if the origin... Pin
Philippe Mori25-Oct-11 13:20
memberPhilippe Mori25-Oct-11 13:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170424.1 | Last Updated 30 Oct 2011
Article Copyright 2011 by steveb
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid