CString to LPCTSTR conversion

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 20:01:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!