If you write a program in the Unicode environment today and convert the cstring to the const char * type, an error is returned: "cannot convert parameter 1 from 'wchar _ T * 'to 'const char *'". After a long search, we finally found three solutions:
First: The following method can be used in the com environment,
Cstring strsql;
Strsql. Format (_ T ('insert into class (name) values ('% s ')'),
M_strname.getbuffer (m_strname.getlength ()));
Char * pchsql = _ com_util: convertbstrtostring (strsql. getbuffer (strsql. getlength ()));
Second:Use the conversion function provided by the operating system,
Int nsize = widechartomultibyte (cp_acp,
Null,
Strsql. getbuffer (strsql. getlength ()),
-1,
Null,
0,
Null,
False );
Char * pchstr = new char [nsize];
Widechartomultibyte (cp_acp,
Null,
Strsql. getbuffer (strsql. getlength ()),
-1,
Pchstr,
Nsize,
Null,
False );
Delete pchstr;
Third: Use the conversion function provided by the C ++ Library:
# Include <stdlib. h>
......
Char pchsql [128] = {0 };
Wcstombs (pchsql, strsql, strsql. getlength ());