wstring CLuaProgramNode::GetLuaNodeString( int iId, wstring sValue)
{
wstring str; int iPropertyId = iId;
wstring sPropertyValue = sValue; if (sPropertyValue != "") // error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::wstring' (or there is no acceptable conversion)
{
wsprintf(str, L"{%d/%s}", iPropertyId, sPropertyValue); //error C2664: 'wsprintfW' : cannot convert parameter 1 from 'std::wstring' to 'LPWSTR'
} return str;
}这两个问题怎么解决呢???要求必须返回wstring,不能用CString中的Format函数来代替。求解决办法!!!!!!!!!!
{
wstring str; int iPropertyId = iId;
wstring sPropertyValue = sValue; if (sPropertyValue != "") // error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::wstring' (or there is no acceptable conversion)
{
wsprintf(str, L"{%d/%s}", iPropertyId, sPropertyValue); //error C2664: 'wsprintfW' : cannot convert parameter 1 from 'std::wstring' to 'LPWSTR'
} return str;
}这两个问题怎么解决呢???要求必须返回wstring,不能用CString中的Format函数来代替。求解决办法!!!!!!!!!!
if(*(sPropertyValue.c_str()))
{
wsprintf((LPWSTR)str.c_str() , L"{%d/%s}", iPropertyId, sPropertyValue.c_str()); //error C2664: 'wsprintfW' : cannot convert parameter 1 from 'std::wstring' to 'LPWSTR'
}
把if (sPropertyValue != "") 改为:if (sPropertyValue != L"") 第二个问题:
wstring 不能作为wsprintf的第一个参数,wsprintf的原型为:
int wsprintf(
LPTSTR lpOut,
LPCTSTR lpFmt,
...
);
你可以另外定义一个缓冲数组,格式化到里边以后,然后再把该格式化的串赋给str.
wstring CTestzwpDlg::GetLuaNodeString( int iId, wstring sValue)
{
wstring str; int iPropertyId = iId;
wstring sPropertyValue = sValue;
TCHAR buffer[256]; if (sPropertyValue != _T("")) // error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::wstring' (or there is no acceptable conversion)
{
wsprintf(buffer, _T("{%d/%s}"), iPropertyId, sPropertyValue); //error C2664: 'wsprintfW' : cannot convert parameter 1 from 'std::wstring' to 'LPWSTR'
}
str = buffer;
return str;
}
{
wchar_t buffer[256] = {0};//使用buffer int iPropertyId = iId;
wstring sPropertyValue = sValue; if (wcscmp(sPropertyValue.c_str(),L""))
{
wsprintf(buffer, L"{%d/%s}", iPropertyId, sPropertyValue.c_str());
} return wstring(buffer);//转换一下
}
wstring CLuaProgramNode::GetLuaNodeString( int iId, wstring sValue)
{
wchar_t buffer[256] = {0};//使用buffer int iPropertyId = iId;
wstring sPropertyValue = sValue; if (wcscmp(sPropertyValue.c_str(),L""))
{
wsprintfW(buffer, L"{%d/%s}", iPropertyId, sPropertyValue.c_str()); //使用宽字节函数
} return wstring(buffer);//转换一下
}
另:5楼的代码也需要修改下。不可以使用_T,当用户在多字节的情况下,会变成
if (sPropertyValue != "") 这很明显编译不过。