Click here to Skip to main content
15,885,713 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.
4.78/5 (2 votes)
13 Nov 2011CPOL 14.1K   4
I am using CString str(_T("Test"));typedef std::basic_string string_t;string_t resStr(str);It works because the CSting has a cast to LPTCSTR.
I am using

CString str(_T("Test"));
typedef std::basic_string<tchar> string_t;
string_t resStr(str);

It works because the CSting has a cast to LPTCSTR.

License

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


Written By
Software Developer Verizon Internet Services
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralYes I do: typedef std::basic_string<TCHAR> string_t. Pin
geoyar9-Nov-11 7:01
professionalgeoyar9-Nov-11 7:01 
Generalstd::basic_string is template class. Did u mean: typedef std... Pin
Kaqkk799-Nov-11 3:41
Kaqkk799-Nov-11 3:41 
Generalstd::basic_string is template class. Did u mean: typedef std... Pin
Kaqkk799-Nov-11 3:39
Kaqkk799-Nov-11 3:39 
Generalstd::basic_string is template class. Did u mean: &lt;pre> ty... Pin
Kaqkk799-Nov-11 3:38
Kaqkk799-Nov-11 3:38 

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.