C++ – What serious alternatives exist for the IOStream library? (besides cstdio)

ciostream

I'm looking for a library which operates similar to iostreams, in that it performs conversions, and allows writing to memory buffers, files, and the console. However, I'd like something type safe, as iostream is. Are there any serious libraries which do this?

Being able to specify the output encoding for things would be a plus.

Note that I'm not interested in libraries which simply front iostreams because they just add more complexity to what iostreams is doing, e.g. boost::format.

PreEmptive comment response: I don't want to use cstdio because using that system it's impossible to have code be output location agnostic. That is, you have to call one function for sending things to buffers, and you have to call another function to send things to files, and another for the console, etc.

EDIT2: In response to the flurry of comments below: I'm fed up with both iostreams and cstdio. Here are more specific reasons. I tried to keep my "rant" out of this question, but people keep asking my if I'm off my rocker, so here's my rationale.

cstdio

  • Can't handle Unicode characters correctly
  • Can't write into something like a string without doing manual buffer management
  • Often requires support of nonstandard extensions (e.g. vsnprintf) in order to be usable (EDIT: Okay, C99's standard library being in C++11 adds most/all of these now)
  • Can't change the location of output without changing the original code (nonstandard extensions e.g. in glibc allow you to treat a file pointer as a buffer, which kind of does this… but it's still just that, a nonstandard extension)
  • Makes security "fun" (to the point where entire chapters are dedicated in security docs explaining issues, e.g. with "printf"'s format strings and such)
  • Not type safe

iostreams

  • Slow
  • Entirely too complicated to a client. If you use only what comes with the standard library it's great, but attempting to extend things is next to impossible. I read the entire "Standard C++ IOStreams and Locales" book — the only book seemingly available on the topic — twice — and I still don't know what's going on.

I love iostreams in concept, even the use of operator<< which some people seem to not like, but it seems entirely too over engineered to me. Someone should not have to spend countless hours reading books in order to be a simple client of your library. Sure, if you're adding a new output source or something like that I could understand, but…. clients should be shielded from that complexity. (Isn't that what a library's for?)

This is about the only thing that's painful in C++ that "just works" in other programming languages, that I see no reason to be complicated.

Best Answer

Boost.Spirit.Qi for input, Boost.Spirit.Karma for output. Can read from/write to anything that can be represented as an iterator range.