A cast won't solve the problem. The std::string is encapsulating a narrow string. So the member function c_str() is returning a const char * pointer. You need to convert the result to UNICODE or otherwise change the code to use std::wstring when building for UNICODE.
LPCTSTR to const char*
Flaviu_
1,031
Reputation points
In a MFC project, I have encoutnered an issue using CDatabase::ExecuteSQL
method, whend I have tried to deliver a std::string
as a parameter:
void ExecuteSQL(LPCTSTR lpszSQL);
std::string sql;
ExecuteSQL(sql.c_str());
in Use Unicode Character Set configuration only.
The error is:
'void CDatabase::ExecuteSQL(LPCTSTR)': cannot convert argument 1 from 'const _Elem *' to 'LPCTSTR'
note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
So, which one of conversion is better ? reinterpret_cast or C-style cast ? Or doesn't matter ?
Developer technologies | C++
3,977 questions