我需要附加一个带有sqlite记录集列条目的字符串,我用这个
char a[16]=(unsigned char *)"Name: "+(unsigned char *)rs.recordset[0][1];
但我一直收到这个错误。
error: invalid operands to binary
+
我做错了什么?
最佳答案
在 C 中,+
符号不连接字符串。
根据 C11
标准,第 §6.5.6 章,加法运算符
For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to a complete object type and the other shall have integer type.[..]
因此,+
不会连接两个字符串。
您需要使用 strcat()
连接两个字符串。
有点像
char a[16] = {0};
strcat(a, "name");
strcat(a, rs.recordset[0][1] );
只要 a
的长度足以正确保存最终输出(连接的字符串),就可以为您完成这项工作。
关于c - 使用 Sqlite 中的记录集条目附加字符串时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35519581/