hi all,
how to convert cstring to string?
thanks!
hi all,
how to convert cstring to string?
thanks!
I'd look in the manual for a suitable cstring method...
Or you could ask Santa to help
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You can access the inner string on CString (I'm assuming you mean the MFC/ATL version) with GetString.
Be very careful though...std::string is often used with 1 byte chars....CString can also be unicode and GetString returns a PCXSTR
Depends on what you do. GetString is rarely, if ever, used.
If you need a const TCHAR*, then all you need to do is pass the object and it will automatically call CString's const TCHAR* function.
If you need a buffer to write to, you call GetBuffer with appropriate size. This will return TCHAR*, so you can write to it. Don't forget to call ReleaseBuffer later to make sure the CString class can handle the new string you've copied into the buffer.
Use CStringA for a GetString() that returns const char*.
Use CStringW for a GetString() that returns const wchar*.
Use CString for GetString() that returns const TCHAR*.
gg