错误C2664:'策略:: Interphase':无法将参数2从'char *'转换为'char * []'

时间:2016-09-05 13:37:25

标签: c++

我从来没能完全绕过指针,字符串,字符等。 我需要帮助解决这个错误。 这是代码片段......

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)

感谢。

1 个答案:

答案 0 :(得分:0)

您的错误:

  

错误C2664:'策略:: Interphase' :无法从' char *'转换参数2到' 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:由通用字符名称' \ u05E9'表示的字符无法在当前代码页(1252)中表示

表示char无法保留非ASCII字符。

如果您正在使用Unicode,则必须使用宽字符和字符串(wchar_twstring)来允许更大的数字。否则,您将拥有overflow并且可能会换行。

链接到comparison between string and wstring

作为旁注,你真的不应该使用C风格的字符串(char*)。 请改用std::string。 原因是:

  • 需要自己解除分配(你的代码按原样泄漏内存)
  • 不安全的api(需要传递大小和数据)