Thanks to Paul V. and Ben Combee for their useful suggestions on how to support line endings (C++ “endl”) and internal format manipulators, respectively, we now have a bona fide Streaming library.
With it, you can now write code like this:
Serial << "A is " << lettera << "." << endl;
lcd << "The date is " << d << "-" << m << "-" << y << ".";
eth << "You can use modifiers too, for example:" << endl;
Serial << _BYTE(a) << " is " << _HEX(a) << " in hex. " << endl;
And thanks very much for all the Arduinians who have used and commented on Streaming. Cool stuff.
The new library is available in the “Libraries” section or here.
Mikal
Albert
15 years ago
Dear Mikal Hart,
I miss some headers that describe your libraries in one line.
The NewSoftSerial and Flash have a headers like this:
NewSoftSerial. The header is: A New Software Serial Library for Arduino
Flash. The header is: A library for ROM-based (PROGMEM) data
Can you add headers to these libraries, here is a suggestion:
Pstring / A lightweight class for handling formatted text
Streaming / A New c++ like Input/Output Stream Library for Arduino
Mikal
15 years ago
That makes some sense, Albert. I like to keep things uniform. Thanks for the suggestion.
Albert
15 years ago
Thanks Mikal for the library,
The Streaming library indeed takes no extra machine code. The generated machine code is the same as with using Serial.print().
Because the Arduino is c++ programmable, stream I/O is an important feature, which is now available. It would be good if this library become part of the Arduino core and added to the Language Reference. Or can you let put your library to the Contributed Libraries list? See here reference\Libraries.html
Albert
Mikal
15 years ago
Albert, thanks for the comments. I tried to suggest to the Arduino staff that this was a useful thing to include in the Arduino core, but they rejected it on the grounds that they want to try to keep a consistent “look and feel”. I would be happy to have the library in the “Contributed Libraries” list, and some of mine are, but I don’t have control over that list.
If you feel strongly about it, I might suggest posting a message on the Arduino Playground.
Thanks again!
Mikal
Albert
15 years ago
Dear Mikal,
Streaming is an important c++ feature, therefore I don’t understand why includement of the Streaming library is rejected. I shall post a message on the Arduino Playground.
I have some improvements for the Flash, PString and Streaming libraries and I found some minor bugs. Look for *Albert in the files for the changes. You can find my files here: http://www.esnips.com/web/Arduino/
Streaming.h
endl improved, uses less machine code.
Maybe you can rename Streaming to ostream.h? This is more familiar with the c++ libraries.
streaming_example.pde
I added an automatic unit test using PString and assert.
I send you the other files soon.
Yours sincerely,
Albert
Maastricht, Netherlands
JlyanYdrael
13 years ago
Hi. is this library for outputting data only ??
in c++ there’s a thing like cin>>data>>data1>>etc..
Can i do it using this or an library? thanks.
any advise would be great. :)
bill rowe
12 years ago
big fan!
How can I use it with a software defined serial port? I’m getting error message
sketch_oct18a.cpp: In function ‘void setup()’:
sketch_oct18a:11: error: no match for ‘operator<<' in 'LCD << "**"'
C:\Users\Bill\Documents\Arduino\libraries\streaming/Streaming.h:51: note: candidates are: Print& operator<<(Print&, const _BASED&)
C:\Users\Bill\Documents\Arduino\libraries\streaming/Streaming.h:69: note: Print& operator<<(Print&, const _FLOAT&)
C:\Users\Bill\Documents\Arduino\libraries\streaming/Streaming.h:80: note: Print& operator<<(Print&, _EndLineCode)