CCS News

Tech Note: C++ Stream Operator Support

Tuesday 27 May, 2014

C++ streams provide a unified interface for IO and data formatting! The two operators within the C-Aware IDE V.5 are the extraction operator and the insertion operator. The '>>' operator is used for formatted extractions while and the '<<' operator is used for formatted insertions. A flexible and simple way to design the input/output routines of any application is through the use of IO streams operators. Through this example the operators show the direction of data:



The beauty of these operators is that the x and y in the above examples can be any combination of function, RS232 serial stream, variable, string and more. Here are some quick and easy of examples of how you can use the C++ Stream Operators in your code:

  • Use this example for a simple RS-232 output of a number:
    cout << "Value is " << value << endl;
  • For output to an LCD the following example code is just as simple:
    lcd_putc << "Value is " << value << endl;
  • Just as easily convert numbers to a string:
    string1 << value;
  • Or strings to a number:
    string1 >> value;
  • Parsing an input line of space delimited numbers is as easy as:
    cin >> value1 >> value2 >> value3;
    Of course integers, floats, int1's and more can be used just as easily as values.
  • Many manipulators are available. For example to output the value in hex use this example:
    cout << "Value is " << hex << value << endl;


For more information on the C++ IO Stream Operator Support functionality please visit:
http://www.ccsinfo.com/iostream

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.