Sub-pages available are:
#include "iof/fmtr.hpp" int main() { std::string world("world"); std::cout << iof::fmtr("Hello %s\n") << world; }
For formatted input:
#include "iof/fmtr.hpp" int main() { std::istringstream inData("123_abc"); int inNumber = 0; std::string inWord; inData >> iof::fmtr("%s_%s") >> inNumber >> inWord; }
std::cout << iof::fmtr("Ground is '%>s' at z=%.2fs\n") << objName << zz;
Without iof you would have to write:
std::cout << "Ground is '" << std::right << objName << "' at z=" << std::iof::precision(2) << std::fixed << zz << std::endl;
Here is a common idiom for formatted input:
std::istringstream input("1_2 3\n4_5 6\n7_8 9\nA B C") iof::fmtr fmtr("%s_%s %s\n"); iof::validity parseOK; int a, b, c; // echo everything that is read: while (input >> fmtr >> a >> b >> c >> ok) std::cout << "Read: " << fmtr << a << b << c; if (!parseOK) std::cout << "Problem at position %s of '%s'" << parseOK.problemPos << parseOK.fmt;
Doing the above input example using raw STL streams would take 100 lines.
But you get much more than just a compact, convenient format representation with iof: you get scoping of stream format, controlled "persistence", format composition, format aggregates, better error status on input operations, etc. And when compared to C's printf/scanf, you get the myriad benefits of STL streams, namely type safety, robustness, etc.
Why not 100% compatibility? Because compared to libraries like iof, printf/scanf are brain-dead. A formatting library can't have its cake and eat it too; i.e., it must give up some power/convenience if it is to be backwards compatible. An example of this: with iof you no longer have to worry about giving type information, since the C++ compiler has it, so all formatting is "%s", rather than "%f" for floats, "%d" for ints, "%uc" for unsigned chars, etc etc.
Version | Changes from previous version |
0.8a | Clean-up, error info for formatted input, better docs |
0.7 | Object-based centering and alignment |
0.6 | Exception safety, better persistence model |
0.5 | First release after branch off from the original "coutf" v1.2 library |