Arduino的string.toCharArray。为什么会收到无效的转换警告?

时间:2018-12-10 16:46:43

标签: c++ string arduino

我正在尝试使用Arduino字符串库的uint8_t函数将Arduino字符串转换为.toCharArray()数组。

这是发生警告的功能:

void sendData(String string) {
  uint8_t buf[string.length()];
  string.toCharArray(buf, string.length());
  rf69.send(buf, sizeof(buf));
}

这是错误:

C:\Users\XX\Documents\Arduino\Transmitter\Transmitter.ino: In function 'int toInt(String)':
C:\Users\XX\Documents\Arduino\Transmitter\Transmitter.ino:42:40: warning: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char*' [-fpermissive]
 string.toCharArray(buf, sizeof(buf));
                                    ^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:231:0,
             from sketch\Transmitter.ino.cpp:1:
 C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:161:7: note:   initializing argument 1 of 'void String::toCharArray(char*, unsigned int, unsigned int) const'
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const

奇怪的是它已经像这样工作了,没有任何错误或警告。

谁能告诉我我在这里做错了吗?

0 个答案:

没有答案