Afficher un message
Vieux 23/02/2008, 17h07   #11
Ioannis Vranos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: wcout, wprintf() only print English

Jeff Schwab wrote:
>
>> 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:
>
> #include <iostream>
> #include <locale>
>
> int main() {
> std::wcout.imbue(std::locale("el_GR.UTF-8"));
> std::wcout << L"Δοκιμαστικό μήνυμα\n";
> }
>
> 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:
>
> #include <iostream>
> #include <locale>
>
> int main() {
> std::cout.imbue(std::locale(""));
> std::cout << "Δοκιμαστικό μήνυμα\n";
> }



"Strangely" these also happen to my Linux box with "gcc version 4.1.2
20070626".

cout prints Greek without the L notation to the string literal.

The same with wcout prints an empty line.

The same with wcout and L notation prints question marks.


This made me think to use plain cout, and it also works:


#include <iostream>

int main()
{
std::cout << "Δοκιμαστικό μήνυμα\n";
}

also prints the Greek message.


Seeing this I am assuming char is implemented as unsigned char and this
is working because Greek is provided in the extended ASCII character set
(values 128-255) supported by my system (I have set the regional
settings under GNOME etc). However why does this also work for you?


The code


#include <iostream>
#include <limits>

int main()
{
using namespace std;

cout<< static_cast<int>( numeric_limits<char>::max() )<< endl;
}

produces in my system:

[john@localhost src]$ ./foobar-cpp
127

[john@localhost src]$


so I am wrong, char is implemented as signed char, and no extended ASCII
takes place.


Strange.
  Réponse avec citation
 
Page generated in 0,06389 seconds with 9 queries