Hi,
I'm trying to convert a wide character string in UTF-8 into a multibyte string using wctomb and I'm running into a problem when I try to convert characters that take more than one byte (ie, non ASCII characters). Below is simple code that produces the problem:
If I substitue a simple character like L'e', then it works as expected, however with either of these more complicated characters (the first is Chinese, second is spanish) wctomb returns -1, meaning it couldn't convert the character. Why?
It fails if I use either the number or the actual letter representation, which makes sense because they are equivalent.
I'm running this on Suse Linux Enterprise Desktop 10 and compiling with g++ 4.1.0.
Thanks,
Andrew
I'm trying to convert a wide character string in UTF-8 into a multibyte string using wctomb and I'm running into a problem when I try to convert characters that take more than one byte (ie, non ASCII characters). Below is simple code that produces the problem:
Code:
#include <iostream> using namespace std; int main() { char buffer[40]; for(size_t i=0; i<40; ++i) buffer[i]=0; // wchar_t wch = L'ア'; (UTF-8 65393) wchar_t wch = L'ñ'; wchar_t wide = 241; cout << wch << endl; int length; if (wch == wide) cout << "Yes!" << endl; length = wctomb( buffer, wch ); printf( "The number of bytes that comprise the multibyte " "character is %i\n", length ); printf( "And the converted string is \"%s\"\n", buffer ); return 0; }
It fails if I use either the number or the actual letter representation, which makes sense because they are equivalent.
I'm running this on Suse Linux Enterprise Desktop 10 and compiling with g++ 4.1.0.
Thanks,
Andrew
Comment