Click here to Skip to main content
15,880,469 members
Articles / Desktop Programming / MFC
Alternative
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
1 Nov 2011CPOL 10.6K   1
How about this (assuming your project is set to Unicode)?CString strMyString=L"Test string";std::string strMyStdAnsiStr = CStringA(strMyString);

How about this (assuming your project is set to Unicode)?

C++
CString strMyString=L"Test string";
std::string strMyStdAnsiStr = CStringA(strMyString);

License

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


Written By
Software Developer (Senior)
Hungary Hungary
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionconvert string to Cstring? Pin
Vijay Kumbhani29-Oct-13 3:05
Vijay Kumbhani29-Oct-13 3:05 

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.