错误 C2664:'Strategy::Interphase':无法将参数 2 从 'char *' 转换为'char *[]'
Error C2664: 'Strategy::Interphase' : cannot convert parameter 2 from 'char *' to 'char *[]'
我从来都不太懂指针、字符串、字符等。我需要帮助解决这个错误。下面是代码片段…
string H = "פטיש";
string G = "Σφυρί";
bool Interphase(int argc, char * args[]); //DLL import from Analytical.a
char * Hcopy = new char[H.length() + 1];
std::strcpy(Hcopy, H.c_str());
char * Gcopy = new char[G.length() + 1];
std::strcpy(Gcopy, G.c_str());
while (Interphase(147, Hcopy) == true || Interphase(148, Gcopy) == true)//C2664 here!
{// Do stuff...}
请注意,代码已更改,仅反映错误。
还有如何在Visual Studio 2012 Ultimate中编译而不使用Warning C4566: character represented by universal-character-name 'u05E9' cannot be represented in the current code page (1252)
谢谢。
您的错误:
错误C2664: 'Strategy::Interphase':无法将参数2从'char *'转换为'char *[]'
意味着你给期望有char*[]
的函数一个char*
。
bool Interphase(int argc, char * args[]);
注意第二个参数,它是指向数组(或数组的数组,或指针指向指针)的指针。
你的代码可以修改为给它指针的地址:
while (Interphase(1, &Hcopy) == true || Interphase(1, &Gcopy) == true)
// ...
,但我怀疑这是如何使用的API。
我不熟悉这个函数,但我猜它更像:
const char** args = {"arg1", "arg2"};
Interphase(2, args);
你的警告:
警告C4566:由universal-character-name 'u05E9'表示的字符无法在当前代码页(1252)中表示
表示char
不能保存非ascii字符。
如果使用Unicode,则必须使用宽字符和字符串(wchar_t
和wstring
)以允许更大的数字。否则,您将出现溢出并可能发生换行。
string
和wstring
的比较链接。
作为旁注,你真的不应该使用c风格的字符串(char*
)。使用std::string
代替。原因:
- 需要自己释放它们(你的代码泄漏内存)
- 不安全的api(需要将大小与数据一起传递)
相关文章:
- 将无符号char*转换为std::istream*C++
- 为什么这个函数将"const char*"转换为"void* const"而不是"const void*"
- 将函数参数"const char*"转换为"std::string_view"是
- C ++如何在使用"tolower"时将char转换为int
- 有没有办法在C++的赋值中将"char**"转换为"double"?
- JavaCPP 错误:无法将参数"1"的"char*"转换为"Abc*
- 为什么从 char 转换为 std::byte 可能是未定义的行为?
- 如何在虚幻引擎4中将char*转换为TCHAR?
- C++:将模板类型 char 转换为 std::string
- strcmp/char* 转换无法按预期工作
- C++中的SQLite char*转换
- 无法从 const char* 转换为 const char *&
- 在 C++ 中将 char 转换为 int,而无需符号位传播
- 如果必须包含西里尔字符,如何将 char* 转换为 std::string?
- 试图使用strCMP时的char转换错误
- 无法从'const char *'转换为'LPCTSTR'
- 将 std::vector<char> 转换为字符* 会导致字符缺陷
- 使用 static_cast 将 char 转换为 int c++
- 如何在 C++(MFC) 中将 char* 转换为 LPCTSTR
- 无法将const char转换为字符串构造字符串