Click here to Skip to main content
Click here to Skip to main content
Alternative Tip
Go to top

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

, 30 Oct 2011
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

Comments and Discussions

QuestionThis conversion is bad! PinmemberTheo Buys1-Nov-13 5:29 
Questionconvert string to Cstring? PingroupVijay Kumbhani29-Oct-13 3:05 
AnswerRe: convert string to Cstring? Pinmembersteveb3-Nov-13 6:57 
BugNot a unicode aware transformation Pinmemberpasztorpisti16-Aug-12 11:52 
GeneralI don't think it would give the desired result if the origin... PinmemberPhilippe 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 | Mobile
Web03 | 2.8.140926.1 | Last Updated 30 Oct 2011
Article Copyright 2011 by steveb
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid