![](/img/trans.png)
[英]Error C2664: 'strcpy' : cannot convert parameter 2 from 'const wchar_t [9]' to 'const char *'.How to solve this error?
[英]'strcpy' : cannot convert parameter 2 from 'WCHAR *' to 'const char *
遇到strcpy問題...
收到此錯誤:
strcpy' : cannot convert parameter 2 from 'WCHAR *' to 'const char *
這是代碼...
char FunctionName[ 256 ];
UFunction *pUFunc = NULL;
strcpy( FunctionName, pUFunc->GetFullName() );
並且:
WCHAR* UObject::GetFullName ()
{
if ( this->Class && this->Outer )
{
static WCHAR ObjectName[ 256 ];
if (Outer == NULL)
{
wsprintf(ObjectName, L"");
}
else
{
if (Outer->Outer)
wsprintf(ObjectName, L"%s %s.%s.%s", Class->Name.GetName(), Outer->Outer->Name.GetName(), Outer->Name.GetName(), Name.GetName());
else if(Outer)
wsprintf(ObjectName, L"%s %s.%s", Class->Name.GetName(), Outer->Name.GetName(), Name.GetName());
}
return ObjectName;
}
return L"(null)";
}
對於WCHAR項目,您需要wcscpy,而不是strcpy。 但是真正的問題是您正在嘗試將寬字符串轉換為窄字符串。 WideCharToMultiByte
因為您似乎在Windows上。
從錯誤中很明顯:strcpy期望將const char*
作為第二個參數,並且您正在傳遞WCHAR*
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.