C++ 无效的转换常量无符号字符
我的程序中有以下功能:C++ 无效的转换常量无符号字符,c++,C++,我的程序中有以下功能: unsigned char * stringXOR(const unsigned char * X, const unsigned char * Y, int len) { unsigned char * result = new unsigned char [1024]; for(int i = 0; i < len; i++) { result[i] = X[i] ^ Y[i]; } result[len]
unsigned char * stringXOR(const unsigned char * X, const unsigned char * Y, int len)
{
unsigned char * result = new unsigned char [1024];
for(int i = 0; i < len; i++)
{
result[i] = X[i] ^ Y[i];
}
result[len] = '\0';
return result;
}
我得到一个错误从“unsigned char*”到“const char*”[-fppermissive]|
这里有什么问题?我没有返回任何常量,所以有什么问题吗?strlen
需要常量字符*
。您正试图将常量unsigned char*
传递给它。这就是错误消息的内容。strlen
需要const char*
。您正试图将常量unsigned char*
传递给它。这就是错误消息的内容。错误不是关于到常量的任何转换,而是关于将指向无符号字符的指针
转换为指向(常量)字符*的指针。错误不是关于到常量的任何转换,它是关于将指向无符号字符的指针
转换为指向(const)char*
的指针。始终提供发生错误的行。读取strlen
是如何指定的。始终提供发生错误的行。读取strlen
是如何指定的。哦,所以我每次使用strlen时都必须将它与其他const char*@lllook一起使用,而不是const char*
-你不应该将strlen
用于char*
或const char*
以外的任何东西。哦,所以每次我使用strlen时都必须将它与其他const char*@lllook一起使用,除了const char*
,您不应该将strlen
用于char*
或const char*
之外的任何东西。
unsigned char ot1[1024] = "ksjdhsjd";
unsigned char ot2[1024] = "jjjkjhyh";
unsigned char * computeKey;
computeKey = stringXOR(ot1, ot2, strlen(ot1));