为什么 LPTSTR lp="sd是的非法fgdfg";
string str=(string)lp;
这个代码在一个类中可以转换成功,而放大同一工程的另一个类中却报如下错误:
错误 1 error C2440: 'initializing' : cannot convert from 'const char [16]' to 'LPTSTR' d:\my documents\visual studio 2005\projects\writeoutlook11_9\writeoutlook1\addcontacts.cpp
错误 2 error C2440: 'type cast' : cannot convert from 'LPTSTR' to 'std::string' d:\my documents\visual studio 2005\projects\writeoutlook11_9\writeoutlook1\addcontacts.cpp
string str=(string)lp;
这个代码在一个类中可以转换成功,而放大同一工程的另一个类中却报如下错误:
错误 1 error C2440: 'initializing' : cannot convert from 'const char [16]' to 'LPTSTR' d:\my documents\visual studio 2005\projects\writeoutlook11_9\writeoutlook1\addcontacts.cpp
错误 2 error C2440: 'type cast' : cannot convert from 'LPTSTR' to 'std::string' d:\my documents\visual studio 2005\projects\writeoutlook11_9\writeoutlook1\addcontacts.cpp
LPTSTR psz(_T("Hello,World"));
string str("");
#ifdef UNICODE
char* buf = NULL;
int len = WideCharToMultiByte(CP_ACP, 0, psz, -1, buf, 0, NULL, NULL);
buf = new char[len];
memset(buf, 0, len*sizeof(char));
WideCharToMultiByte(CP_ACP, 0, psz, -1, buf, len, NULL, NULL);
str += buf;
delete[] buf;
#else
str = psz;
#endif
AfxMessageBox(CString(str.c_str()));