简体   繁体   English

错误:从不兼容类型'const char *'分配给'char'

[英]error: assigning to 'char' from incompatible type 'const char *'

I am getting this error when trying to compile my code. 尝试编译代码时出现此错误。

error: assigning to 'char' from incompatible type 'const char *' 错误:从不兼容类型'const char *'分配给'char'

The function in reference is 参考中的功能是

void stringCopy(char *destination, const char *source) {
   while(source != '\0') {
       destination = source;
       destination++, source++;
    }
}

I do know there is a built in strcpy() in C++ but for what I am doing, it was requested that we make one from scratch. 我确实知道C ++中有一个内置的strcpy() ,但是对于我正在做的事情,要求我们从头开始制作一个。

The variable source is a pointer to a character. 变量source指向字符的指针

The identifier '\\0' is a character . 标识符'\\0'是一个字符

In the while expression, you are comparing a pointer to a character. while表达式中,您正在将指针与字符进行比较。

You can get the character by dereferencing the pointer: 您可以通过取消引用指针来获取字符:

while (*source != '\0')

In the copy statement, you are copying pointers, not characters. 在copy语句中,您正在复制指针,而不是字符。

Review your favorite C++ reference about pointers. 查看您最喜欢的有关指针的C ++参考。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 c ++错误:从不兼容的类型'const char *'分配'char *' - c++ error: assigning to 'char *' from incompatible type 'const char *' 错误:从不兼容类型void *分配给char * - Error: Assigning to char* from incompatible type void* 我感到困惑,为什么我的fillDeck函数说“从不兼容的类型'const char *分配给'char *'” - I am confused why my fillDeck function says, “assigning to 'char *' from incompatible type 'const char *” 从不兼容类型“ void”分配给“ char” - Assigning to 'char' from incompatible type 'void' 将 const char* 分配给 char* - Assigning const char* to char* “ const char **”类型的参数与“ const char *”类型的参数不兼容 - Argument of type “const char **” is incompatible with parameter of type “const char *” setter 方法出错:“const char *”类型的参数与“char *”类型的参数不兼容 - Error with setter method: argument of type "const char *" is incompatible with parameter of type "char *" “unsigned char *”类型的参数与“const char *”类型的参数不兼容 - Argument of type "unsigned char *" is incompatible with parameter of type "const char *" 类型“ const char *”的参数与类型“ char *”的参数不兼容。 但为什么? :( - Argument of type “const char*” is incompatible with parameter of type “char*”. But why? :( “const char *”类型的参数与“char *”类型的参数不兼容 - Argument of type “const char *” is incompatible with parameter of type “char *”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM