Click here to Skip to main content
11,434,695 members (46,695 online)
Click here to Skip to main content
Alternative Tip/Trick

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

, 13 Nov 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

geoyar
Software Developer
United States United States
No Biography provided

Comments and Discussions

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

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
Web04 | 2.8.150428.2 | Last Updated 13 Nov 2011
Article Copyright 2011 by geoyar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid