Well I created the file with anjuta editor with the message being a
Greek one. The Greek message also appears the same when I display the
source file in the console.
>>Ioannis Vranos wrote:
>>>Has anyone actually managed to print non-English text by using wcout or
>>>wprintf and the rest of standard, wide character functions?
>>>
>>For example:
>>>
>>[john@localhost src]$ cat main.cc
>>#include <iostream>
>>>
>>int main()
>>{
>> using namespace std;
>>>
>> wcout<< L"Î”Î¿ÎºÎ¹Î¼Î±Ï ƒÏ„ικό μήνυμα\n" ;
>>
>Are you sure that you stored your source file in the same encoding the
>compiler expects as source character set?
>>
>
>
Well I created the file with anjuta editor with the message being a
Greek one. The Greek message also appears the same when I display the
source file in the console.
>
I suppose it is saved as UTF8.
>
>
Also the code
>
#include <iostream>
#include <string>
>
int main()
{
using namespace std;
>
wstring s;
>
wcin>s;
>
>
wcout<< s<< endl;
}
>
>
displays nothing when I enter greek text.
both in g++ under Linux and VC++ 2008 Express under Windows, with the
latest saving the source code file as Unicode after it detected
non-english text.
>>>For example:
>>>>
>>>[john@localhost src]$ cat main.cc
>>>#include <iostream>
>>>>
>>>int main()
>>>{
>>> using namespace std;
>>>>
>>> wcout<< L"Äïêéìáóôéê ü ìÞíõìá\n";
>>>
>>Are you sure that you stored your source file in the same encoding the
>>compiler expects as source character set?
>>>
>>>}
>>>>
>>>[john@localhost src]$ ./foobar-cpp
>>>?????????? ? ??????
>>>>
>>>[john@localhost src]$
>>
>>
>Well I created the file with anjuta editor with the message being a
>Greek one. The Greek message also appears the same when I display the
>source file in the console.
>>
>I suppose it is saved as UTF8.
>>
>>
>Also the code
>>
>#include <iostream>
>#include <string>
>>
>int main()
>{
> using namespace std;
>>
> wstring s;
> wcin>s;
>>
> wcout<< s<< endl;
>}
>>
>>
displays the Greek text when I enter it, but outputs nothing. With
English text, the text is displayed both when entered and outputed.
[john@localhost src]$ ./foobar-cpp
Äïêéìáóôéêü
[john@localhost src]$ ./foobar-cpp
Test
Test
[john@localhost src]$
both in g++ under Linux and VC++ 2008 Express under Windows, with the
latest saving the source code file as Unicode after it detected
non-english text.
>
>
>Has anyone actually managed to print non-English text by using wcout
>or wprintf and the rest of standard, wide character functions?
>
>
For example:
>
[john@localhost src]$ cat main.cc
#include <iostream>
>
int main()
{
using namespace std;
>
wcout<< L"Äïêéìáóôéê ü ìÞíõìá\n";
}
>
[john@localhost src]$ ./foobar-cpp
??????????? ??????
>
[john@localhost src]$
Hmmm... I work almost entirely in English, so this error message is new
to me:
$ make
g++ -ansi -pedantic -Wall main.cc -o main
main.cc: In function 'int main()':
main.cc:4: error: converting to execution character set: Invalid or
incomplete multibyte or wide character
make: *** [main] Error 1
On Sat, 23 Feb 2008 13:11:09 +0200, Ioannis Vranos
<ivranos@nospam .no.spamfreemai l.grwrote:
[...]
>>Also the code
[...]displays the Greek text when I enter it, but outputs nothing. With
English text, the text is displayed both when entered and outputed.
I don't remember anymore the details but the problem has something to do
with codecvt: Your wide characters are automatically converted to narrow
characters by wcout. This is something you might not want (and even if you
want it the conversion might not work automatically the way you expect :).
Try writing to wstringstream and converting to UTF-8 explicitly (storing
the result eg. in string). If your console supports UTF-8 you can print to
cout (otherwise print to a file so you can test the output in an editor).
>
Hmmm... I work almost entirely in English, so this error message is new
to me:
>
$ make
g++ -ansi -pedantic -Wall main.cc -o main
main.cc: In function 'int main()':
main.cc:4: error: converting to execution character set: Invalid or
incomplete multibyte or wide character
make: *** [main] Error 1
Perhaps when you copy and paste the greek text, you copy garbage (that
is, not viewing the message in the correct character set in your
newsgroup reader).
So, I repost the code in this message which is encoded to Unicode (UTF-8):
>>
>Hmmm... I work almost entirely in English, so this error message is
>new to me:
>>
>$ make
>g++ -ansi -pedantic -Wall main.cc -o main
>main.cc: In function 'int main()':
>main.cc:4: error: converting to execution character set: Invalid or
>incomplete multibyte or wide character
>make: *** [main] Error 1
>
>
I tried the same:
>
[john@localhost src]$ g++ -ansi -pedantic-errors -Wall main.cc -o
foobar-cpp
>
[john@localhost src]$
>
>
Perhaps when you copy and paste the greek text, you copy garbage (that
is, not viewing the message in the correct character set in your
newsgroup reader).
>
>
So, I repost the code in this message which is encoded to Unicode (UTF-8):
>
>
#include <iostream>
>
int main()
{
using namespace std;
>
wcout<< L"Î”Î¿ÎºÎ¹Î¼Î±Ï ƒÏ„ικό μήνυμα\n" ;
}
Thanks, you were correct.
Here's what I thought was "supposed" to be the portable solution:
However, my system still shows question marks for this. For whatever
it's worth, here's the (probably incorrect) way that appears to work on
my system:
It looks like GCC has the opposite stuff, cout, cin, string work as
wcout, wcin, wstring and vice versa! Bug?
....
Conclusion: It appears GCC has the wide character stuff messed up, or I
am missing important knowledge.
You and me both. I would be very surprised if this were a GCC bug (I'm
using 4.2.4 pre-release), but I'm guessing somebody here knows a lot
more about this than we do, and is willing to enlighten us. :)
Comment