
Alf P. Steinbach wrote: On 28.10.2011 12:36, Yakov Galka wrote:
This is because windows narrow-chars can't be UTF-8. You could make it portable by:
int main() { boost::printf("Blåbærsyltetøy! 日本国 кошка!\n"); }
Thanks, TIL boost::printf.
No, I don't think that this works. The problem here is not the printf call, it's the literal. When a char[] that does contain the proper UTF-8 text is passed, printf works under chcp 65001. In principle, you should still need to use the hypothetical boost::printf, though, if you want the program to properly support arbitrary code pages (not that the text above can be output in any code page other than 65001).
When every portability problem has been diagnosed and special cased to use functions that translate to/from UTF-8 translation, and ignoring the efficiency aspect of that, then UTF-8 just magically works, hurray.
E.g., if 'fopen( "rød.txt", "r" )' fails in the universal UTF-8 code, then just replace with 'boost::fopen', or 'my_special_casing::fopen'.
Yes, exactly. It's not a silver bullet, but... try coming up with a better alternative.