Springe zum Inhalt

Konvertieren zwischen CString und std::string

Q: How to convert between 'CString' and 'std::string'?


'CString' to 'std::string':

'std::string' to 'CString':

std::string cannot always construct from a LPCTSTR i.e. the code will fail for UNICODE builds.

As std::string can construct only from LPSTR / LPCSTR, a programmer who uses VC++ 7.x or better can utilize conversion classes such as CT2CA as an intermediary.

Like this: