[英]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.