What would be the simplest way for me to copy a CString to a LPTSTR?
LPSTR pszText; //"This is type of LPSTR";
CString cs = "This is a test";
I want both variables to contain "This is a test". Thanks for any suggestions.
JD
Printable View
What would be the simplest way for me to copy a CString to a LPTSTR?
LPSTR pszText; //"This is type of LPSTR";
CString cs = "This is a test";
I want both variables to contain "This is a test". Thanks for any suggestions.
JD
i ran into the same problem and i think i fixed it usin GetBuffer.
try this:
LPSTR pszText = cs.GetBuffer(cs.GetLength());
tell me if it works
CString has overloaded operator LPCTSTR. use that.
e.g.
LPSTR pszText; //"This is type of LPSTR";
CString cs = "This is a test";
pszTest = (LPSTR)(LPCTSTR)cs; //This will do the job; but will only return internal CString pointer
// If u want another copy of cs then try this
pszText = new TCHAR[cs.GetLength() + 1];
_tcscpy(pszText, (LPCTSTR)cs);
Using GetBuffer will result in locking the CString object and any further modifications
will be lost untill u call ReleaseBuffer. Use the reply that I've posted before.
Yogen M, thanks for your post. Works great!
JD
laiason5, thanks for your post. It seems to work fine. See the reply to your post. Due to the locking problem, I am using the other method. I sure appreciate your reponse.
JD