最佳答案
CString
is quite handy, while std::string
is more compatible with STL container. I am using hash_map
. However, hash_map
does not support CString
s as keys, so I want to convert the CString
into a std::string
.
Writing a CString
hash function seems to take a lot of time.
CString -----> std::string
How can I do this?
std::string -----> CString:
inline CString toCString(std::string const& str)
{
return CString(str.c_str());
}
Am I right?
EDIT:
Here are more questions:
How can I convert from wstring
to CString
and vice versa?
// wstring -> CString
std::wstring src;
CString result(src.c_str());
// CString -> wstring
CString src;
std::wstring des(src.GetString());
Is there any problem with this?
Additionally, how can I convert from std::wstring
to std::string
and vice versa?