I am trying to write cross platform i18n C++ code. Since most linux system prefer to use UTF-8 as the character encoding, I thought that I should use string on linux and wstring on Windows. Is tchar.h available on linux? What is an equivalent replacement on for tchar.h on Linux?
+1
A:
You may find this article to be useful. In particular, near the end they discuss a bit about using TCHAR and dealing with Windows code.
McWafflestix
2009-05-21 23:42:54
To be clear, tchar.h is Windows only. But it's fairly trivial to roll your own tchar.h.
Naaff
2009-05-21 23:45:35
A:
It's actually not that easy. string.size() will give you the number of UTF-8 bytes, not Unicode characters. In all fairness, wstring.size() won't give you the number of characters either in the presence of surrogates. But in practice, those are not used in common apps.
So, the real answer really depends on why you need the Unicode strings. Is it just localization of a UI? Do you have user input? Do you need to parse that input?
MSalters
2009-05-22 09:00:23