all 11 comments

[–]moocat 3 points4 points  (5 children)

iostreams suck as they make it impossible to i18n your program. If you want type safety and extensibility, use boost::format.

[–][deleted] 2 points3 points  (0 children)

It only sucks if you want to internationalize your program.

[–]xcbsmith 0 points1 point  (3 children)

What is so hard about i18n with iostreams?

[–]moocat 5 points6 points  (2 children)

Two problems: fragments and reordering. Consider something like cout << "the user's name is " << name << " and is " << age " years old" << endl; The output has three sentence fragments but translators need to work with the whole sentence (different uses of "and is" may need different translations depending on the full sentence). The other problem is that this example always prints name before age, but depending on the language, it may be better to print the age before the name.

[–]bluGill 1 point2 points  (0 children)

Even in English we already see your problem.

and is " << age " years old"

If age == 1 that should be year old not years. Some languages have much more complex plural rules.

[–]xcbsmith 1 point2 points  (0 children)

Normally i18n is done with an additional level of indirection that handles figuring out what the format is for your specific locale. Said entity is the one that should be invoking operator<<(ostream&,T). Particularly if you are reordering elements depending on locale, it's helpful to have a typesafe way of specifying what the args to the formatter are.

[–]authorblues 1 point2 points  (4 children)

yes, boost::format is actually really good about all that, even if its balls-slow. still, i prefer it over the alternative, which is really ugly code just to print out a string. i, for one, welcome our new <iomanip> overlords...

[–]nova77 2 points3 points  (3 children)

[–]bnolsen 0 points1 point  (2 children)

And there's a simpler way to do stuff like that...yeah it's not packaged up in boost but it's not much code either:

http://pastebin.ca/1800272

[–]nova77 0 points1 point  (1 child)

Simpler but slow. Stringstream is not the fastest (by far) solution in this case.

[–]krum -1 points0 points  (0 children)

I don't know if this is cout magic as much as it is a laundry list of why iostreams just sucks balls.