Click here to Skip to main content
11,629,614 members (65,956 online)
Click here to Skip to main content

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

, 30 Oct 2011 CPOL 11K 2
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());
In UNICODE:

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

License

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

Share

About the Author

steveb
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    Rant Rant    Admin Admin   

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150723.1 | Last Updated 30 Oct 2011
Article Copyright 2011 by steveb
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid