类型的无效操作数' const char *'和' const char [2]'到二进制'运算符+'

时间:2016-08-20 14:56:05

标签: c++ gps lora

使用带有LoRa收音机的Adafruit Feather M0板,我想将GPS位置发送到接收器。当尝试创建具有ISO 8601时间戳和纬度/经度GPS值的数据包时,我使用以下代码创建char数组,然后发送它:

char radiopacket[40] = {GPS.year + "-" + GPS.month + "-" + GPS.day + "T" + GPS.hour + ":" + GPS.minute + ":" + GPS.seconds + "Z" + "," + GPS.latitude + "," + GPS.longitude};
rf95.send((uint8_t *)radiopacket, 40);

我一直收到错误:

  

类型的无效操作数' const char *'和' const char [2]'二进制   '操作者+'

我哪里错了?

2 个答案:

答案 0 :(得分:0)

你不能在C中连接类似的字符串。尝试像

这样的东西
char radiopacket[40];
sprintf(radiopacket, "%04d-%02d-%02dT%02d:%02d:%02dZ,%f,%f", GPS.year, GPS.month, GPS.day, GPS.hour, GPS.minute, GPS.seconds, GPS.latitude, GPS.longitude); 
rf95.send((uint8_t *)radiopacket, 40);

有关"%04d-..."

中格式字符串(sprintf)的一些文档,请参阅here

答案 1 :(得分:0)

我会猜测并说你是来自python。

我认为你需要的是 std::stringstream

相关问题