I'm a long time C/C++ programmer who's a dyed in the wool printf user. I've seen how the streaming library can help save resources but I don't see how to format the streamed output.
For example how can I left justify a number, or make it a fixed width?
I'm a long time C/C++ programmer who's a dyed in the wool printf user.
sprintf is available on the Arduino. The %d format specifier is not supported, but most others are.
I've seen how the streaming library can help save resources but I don't see how to format the streamed output.
Which library? How does it "save resources"?
I've got printf working by mapping stdout to Serial using fdevopen(). That's what I'm using at the moment but obviously it pulls in the whole printf stuff from the library.
I've never used the streaming operators in C++ but this:
got me interested. Especially with using the Serial.print overloads to allow it to work with the flash memory library
Because the operator functions are essentially just inline aliases for their print() counterparts, no sketch gets larger or consumes more RAM as a result of their inclusion.
Not using more resources and "saves resources" are not the same thing.
But using the streaming library instead of printf would save program space. The only reasons I'm sticking with printf is because it's familiar and I don't know how to format fields using the insertion operators.
All I'm looking for is a method to justify a number and control it's width.
The formatting streams library does not do any formatting. All it does is generate the individual calls to whatever.print(). You still need to generate the formatted data to stream, using (s)printf.