CCS News RSS

Click here to view the PDF newsletters. Interested in receiving our newsletters in your inbox? Click here to subscribe.

You Stream, I Stream, we can all C++ Stream!

Friday 02 November, 2012

Why should you try the C++ Stream I/O operator support in the CCS Compiler? As you know, in standard C, basic I/O are handled by functions like getc(), putc() and printf() and the formatting of data is handled by functions like atoi(), atof(), strotul() and sprintf(). For example, reading a floating point number from the user over RS232 would require a combination of gets() followed by atof(). While CCS includes an input.c library that accomplishes many of these tasks, the input.c library uses a fixed RS232 stream and does not work with Keypad/LCD or USB without modification. Introducting in Version 5 of the CCS C Compiler, there is added support for the C++ stream operator. C++ streams provided a unified interface for I/O and data formatting.

The two new opreators added are the extraction operator and the insertion operator:



Operator SymbolOperator Name
>>Extraction
<< Insertion


When used, these operators show the direction of data. For example:


ExampleComment
x>>yData read/parsed from x and saved/sent to y
x<<yData read/parsed from y and saved/sent to x


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.

One of the key features of this new feature in the CCS C Compiler is the way it automatically handles the conversion based upon the data types of the variables passed. These conversions are done automatically, no other helper functions like atof() need to be called. For example, if a variable is of float type the compiler will properly convert it from string to float on an input or convert float to string on an output.

Read all the additional details on output and see examples of C++ Streaming by clicking through to: Version 5

A few examples:


cout << fvar << endl;// Display a floating point variable
cin >> fvar;// Read in a float
lcd_putc << "count=" << count;// send to LCD
string1 >> fvar;// string to float conversion


Additional configurations and control options will also be available in Version 5. Feel free to contact us with any comments or questions about the serial library upgrades.....(support@ccsinfo.com)
Want to be a beta tester* for Version 5.... or make suggestions on what you would like to see in Version 5....click thru to the above link!

*All customers with active maintenance are eligible to apply for V.5 betas.
All customers with active maintenance when V.5 is released will receive V.5 at no additional cost.

Resources
To learn more about CCS's C Compiler, visit: Our Compiler Page

To see more helpful hints and tips, visit: Our FAQ Page or Our Customer Forum


Follow us on Facebook and Twitter

 Displaying 11 to 11 (of 11 articles)   Result Pages: [<< Prev]   1  2