错误:二进制+字符的无效操作数* [英] error: invalid operands to binary + char *
本文介绍了错误:二进制+字符的无效操作数*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
C字符串串联
具有以下代码:
char *doencode(const unsigned char *input, int length)
{
//irrelevant code
}
char *fname, *lname;
char *encoded, *name;
name = fname + "|" + lname;
encoded = doencode(name, 30);
我得到这个错误:无效的二进制操作数+
and I get this error: invalid operands to binary +
如何将fname& | & lname?
How can I combine fname & | & lname?
推荐答案
您无法连接 char *
和 char []
( |
)或使用的任何排列+
。使用 strncat()
或 snprintf()
而是确保目标缓冲区有足够的内存来存储最终字符串。
You cannot concatenate char*
and char[]
(the "|"
) or any permutation of using +
. Use strncat()
or snprintf()
instead and ensure the destination buffer has enough memory to store the final string.
这篇关于错误:二进制+字符的无效操作数*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文