Arduino cannot convert 'float' to 'const char*' in initialization

Posted by Lorie Orum on Monday, May 20, 2024
float diff = 0; const char* str[] = {"Err: ZPROBE: ",diff}; LCD_ALERTMESSAGEPGM(str); 

With the code above I get I get this error. Anyone know how to create a single string from "Err: ZPROBE: " and a (float) diff?

exit status 1 cannot convert 'float' to 'const char*' in initializatio 

Sorry should add that in the environment i'm using - 'string' : is not a member of 'std',

Ok now trying this

String str = String("Err: ZPROBE: " , diff); 

but get this

call of overloaded 'String(const char [14], float&)' is ambiguous 
13

1 Answer

To convert float or double into a string, you can use dtostrf() which is available in the stdlib.h header. Also see the reference of String Object Constructors to construct String objects correctly.

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoa29vZGuEdYWOmqmdrZmjvG6vwKelqKxdmLyvwsSrq2aenKSutXnTqGScp56owW6vx5qpZqGeYravtdOimKWhqpbBqrvN