Possible Duplicate:
C++ std::string conversion problem on Windows
How to convert std::string to LPCSTR?
I want to rename a window ( WM_SETTEXT ) to something else. In have a std::string that contains the new window name. I need to convert the std::string to “LPCTSTR”, this is becouse SendMessage needs the name in “LPCTSTR”.
I can’t get this to work, Could some one help me to convert a string to a LPCTSTR?
Use the
c_str()method ofstd::string. This returns a C string, i.e. a pointer to a null-terminated character array.This is fine if you are compiling for ANSI. If you are compiling for Unicode then you should use
wstringinstead ofstring. If that’s the case, just change towstringand the call toSendMessageworks exactly as written above.