问题
I have a CString variable that i a need to convert to LPCTSTR(const char*) .I need this conversion so that i can use it as an argument in a function .
The CString look like :
CString sqlTemp = _T("INSERT INTO "+ sw1 +" (filename, "+ sw2 +") VALUE ("+ sw7 +","+ sw3 +" ) ");
It contains an query. The prototype of the function is :
int WriteBlob(LPCTSTR szSqlStat, LPCTSTR szFilePath)
So could you show me an exemple of how to convert to LPCTSTR ? It may be trivial but i am a c++ beginner and i still get a hang of it.
Thanks .
回答1:
One method of conversion is like this:
CString str;
str = "Hello";
LPCSTR szTemp = (LPCSTR)(LPCTSTR)str;
回答2:
CString str; // the given string
CStringA strA(str); // a helper string
LPCSTR ptr = strA;
Reference MSDN
来源:https://stackoverflow.com/questions/12620820/cstring-to-lpctstr-conversion