0

我正在使用这个库将浮点数转换为字符串: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:错误:“,”标记之前的预期主表达式
.../floatToString.h: 在函数'char* floatToString(char*, float, int, int, bool)'中:
.../floatToString.h:11: 错误:'char* floatToString(char*, float, int, int, bool)' 的参数 5 缺少默认参数
.../floatToString.h:73:错误:未在此范围内声明“itoa”
.../floatToString.h:89:错误:未在此范围内声明“itoa”
4

3 回答 3

0

default argument missing for parameter 5 of 'char* floatToString(char*, float, int, int, bool)

看起来您缺少一个值:floatToString(str, flt, 2, 10)

尝试在末尾添加TrueFalse

于 2010-07-07T19:18:57.520 回答
0

在 C++ 中,仅允许所有最后的参数具有默认值:

BAD rightjustify 必须有一个默认值:

char * floatToString(char * outstr, float value, int places,
    int minwidth=0, bool rightjustify) {

OK:无默认值,最后一个或两个最后一个参数有默认值

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>缺少一个,我会将它放在标题中,因为它取决于它。

于 2010-07-07T19:28:08.483 回答
0

我有同样的错误信息;事实证明我有两次#included "floatToString.h",一次在我的 .ino 文件中,一次在我使用的类之一中。我删除了其中一个,然后(相当误导的)错误消息消失了!

于 2013-05-01T23:03:57.547 回答