CString to LPCTSTR conversion

2019-04-06 00:38发布

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 .

2条回答
劫难
2楼-- · 2019-04-06 01:01
CString str; // the given string
CStringA strA(str); // a helper string
LPCSTR ptr = strA;

Reference MSDN

查看更多
倾城 Initia
3楼-- · 2019-04-06 01:07

One method of conversion is like this:

CString str;

str = "Hello";

LPCSTR szTemp = (LPCSTR)(LPCTSTR)str;
查看更多
登录 后发表回答