How do you convert CString and std::string std::wstring to each other?

According to CodeGuru: CString to std::string: BUT: 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. std::string to CString: (From Visual Studio’s … Read more

Using C-string gives Warning: “Address of stack memory associated with local variable returned”

Variable char* matches[1]; is declared on stack, and it will be automatically released when current block goes out of the scope. This means when you return matches, memory reserved for matches will be freed, and your pointer will point to something that you don’t want to. You can solve this in many ways, and some of them are: Declare matches[1] as static: static char* … Read more