Streaming Print Function, In Arduino Programming Language
Streaming in Arduino Programming Language:
Possible by "streaming" library, newest version of which is v5, which is Arduino 1.0 compatible.
Newer Arduino users might sometimes wonder why “Arduino programming language” doesn’t have the kind of concatenation or streaming operations they have become accustomed to in VB/C++/Java, etc.
// This will not work in Arduino & will surely gives error lcd.print("The button was pressed " + counter + " times");
//lcd.print() is available in LCD library.
Meanwhile, programmers have to synthesize streams with blocks of repetitive code like this:
lcd.print("APP #"); lcd.print(number); lcd.print(" DD: "); lcd.print(dd); lcd.print("-"); lcd.print(MM); lcd.print("-"); lcd.println(YY);
The Streaming library gives you the option of compressing those into “insertion style” code that result concatenation of the above:
lcd << "APP #" << number << " DD: " << dd << "-" << MM << "-" << YY << endl;
Similarly this library works for any class that derives from Print:
Serial << "xyz: " << xyz; lcd << "Pressure: " << t.get_Pressure() << " pascals"; my_string_to_print << "Hello!" << endl;
With this library you can also use formatting manipulators like this:
Serial << "Byte value: " << _HEX(b) << endl; lcd << "The key pressed was " << _BYTE(c) << endl;
This syntax is familiar to many, is easy to read and learn, and, importantly,
consumes no resources.(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.)