我正在使用此库将float转换为字符串:http://www.arduino.cc/playground/Main/FloatToString?action=sourceblock&ref=1。
这是代码片段,其中打印出flt看起来像“29.37”:
float flt = tempSensor.getTemperature();
char buffer[25];
char str[20];
Serial.print(floatToString(str, flt, 2, 10));
这应该是开箱即用的,但不是 - 我做了什么拧?这些是我的编译错误:
.../floatToString.h:11: error: expected primary-expression before ',' token .../floatToString.h: In function 'char* floatToString(char*, float, int, int, bool)': .../floatToString.h:11: error: default argument missing for parameter 5 of 'char* floatToString(char*, float, int, int, bool)' .../floatToString.h:73: error: 'itoa' was not declared in this scope .../floatToString.h:89: error: 'itoa' was not declared in this scope
答案 0 :(得分:0)
default argument missing for parameter 5 of 'char* floatToString(char*, float, int, int, bool)
您似乎错过了一个值:floatToString(str, flt, 2, 10)
尝试在此处添加True
或False
答案 1 :(得分:0)
在C ++中,只允许所有最后一个参数都有一个默认值:
BAD rightjustify必须有一个默认值:
char * floatToString(char * outstr, float value, int places,
int minwidth=0, bool rightjustify) {
确定:没有默认值,最后一个或最后两个参数具有默认值
char * floatToString(char * outstr, float value, int places,
int minwidth, bool rightjustify) {
char * floatToString(char * outstr, float value, int places,
int minwidth, bool rightjustify=false) {
char * floatToString(char * outstr, float value, int places,
int minwidth=0, bool rightjustify=false) {
检查您的标题,我猜您链接的标题不是您当前使用的标题。
还有另一个指向问题的指针:编译器不知道ito。它应该在cstdlib
中,因此缺少#include <cstdlib>
,我会将其放在标题中,因为它取决于它。
答案 2 :(得分:0)
我有同样的错误消息;事实证明我有#included“floatToString.h”两次,一次在我的.ino文件中,一次在我使用的一个类中。我删除了其中一个,然后(相当误导)错误消息消失了!