Why formatted I/O, why IOF

The iof library combines the best of C and C++ worlds: the compactness of printf/scanf formatted input/output, with the robustness and object-oriented capabilities of STL's streams.

Formatted I/O is more compact than raw STL stream I/O: each formatting operation that normally requires STL stream manipulators has a one-character counterpart in iof format strings. Also, you get automatic restoration of stream format state if an exception occurs during input/output, group formatting requires one character (would require several lines of code), some formatting applies to whole object rather than setting state, etc.

Compactness allows the "pattern" of the input or output to be clearer and easier to manage. In some ways, it segregates formatting from content and algorithm. So iof makes it easy to do in a few characters what would take many lines of code to do with "raw" STL streams. This should be appearent in Hello World.

Formatted I/O is more memory-friendly than raw STL stream I/O: I find it much easier, for some reason, to remember that fixed point output is "f" and the number n of digits after period is ".n", than to remember the manipulator names or stream methods to call (e.g. std::ios::fixed and std::setprecision()). This means that you are inclined to format output much more than you would with raw STL streams.

Formatted I/O with iof is more robust than with printf/scanf: iof just uses STL streams behind the scenes, and streams are typesafe. This means you don't need to tell iof what type of object is being output/input, the C++ compiler already knows. You can concentrate on using simple format markers ("%s") to set the state of the stream, regardless of type, and use format specification characters as appropriate, without fear of crashes.

Formatted I/O with iof is more versatile than printf/scanf: you don't need to tell it the type of the object being output, the I/O is exception-aware, there are more operations available (e.g., centering, any character can be used as a filler, booleans can be input or output as words, etc), some operations apply to whole objects (this is even better than raw STL stream I/O), user-data-types can be output as well (instead of just plain old data types like int, float char etc).

Formatted I/O with iof is even more versatile than raw STL stream I/O: iof manages formatting so it doesn't "leak" past the format operation, i.e. your formatting only affects the stream format state for the line on which it is used; the format state is exception safe; some formatting applies to whole objects rather than just set state; input has better error handling available and individual characters can be checked for input; etc.

Generated on Fri Nov 24 16:16:01 2006 for IOF Library by doxygen 1.5.1-p1
Thanks to SourceForge.net Logo for hosting