I wrote this test program in a Latin-1 encoded file...
#include <cstring>#include <iostream>using namespace std;const char str[] = "ÅÄÖ";int main() { cout << sizeof(str) << ''<< strlen(str) << ''<< sizeof("Åäö") << ''<< strlen("åäö") << endl; return 0;}
...and compiled it with g++ -fexec-charset=UTF-8 -pedantic -Wall
on OpenBSD 5.3. I was expecting to see the size of the strings being 6 chars + 1 NUL char, but I get the output 4 3 4 3
?
I tried changing my system locale from ISO-8859-1 to UTF-8 with export LC_CTYPE=sv_SE.UTF-8
, but that didn't help. (Accordning to the gcc manual, that only changes the input character set, but hey, it was worth a try.)
So, what am I doing wrong?