This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/14623] New: UTF-8 encoding, wcout vs. file
- From: "bkoz at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Mar 2004 23:17:02 -0000
- Subject: [Bug libstdc++/14623] New: UTF-8 encoding, wcout vs. file
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This is taken from the FC1 / Red Hat bug tracking system. It's #112192
For the following program:
#include <fstream>
#include <iostream>
#include <locale>
#include <string>
#include <cstdlib>
#include <cerrno>
using namespace std;
int main()
{
wchar_t dst[256];
unsigned char *ptr = (unsigned char *) dst;
char *src = "Tämä on öäåÖÄÅ testi\n";
locale::global(locale("en_US.UTF-8"));
cout << locale().name() << endl;
wcout.imbue(locale());
cout.imbue(locale());
//typedef std::codecvt_byname<wchar_t, char, std::mbstate_t> Cvt;
//const std::locale unicode(std::locale ("C"), new Cvt("UTF-8"));
int i = mbstowcs(dst, src, 255);
printf(">%d< %d\n", i, sizeof(dst));
for (int x=0; x<i*4+1; x++)
printf("%02hx ", ptr[x]);
printf("\n===\n%s%ls===\n", src, dst);
wofstream myfile;
myfile.imbue(locale());
myfile.open("log.log");
perror("0");
wcout << L"Testi " << endl << dst << endl;
perror("1");
errno=0;
myfile << L"Rivi 1 " << endl << dst << endl;
perror("2");
myfile.close();
}
On FC1, I'm getting:
----------------start
en_US.UTF-8
>21< 1024
54 00 00 00 e4 00 00 00 6d 00 00 00 e4 00 00 00 20 00 00 00 6f 00 00 00 6e 00 00
00 20 00 00 00 f6 00 00 00 e4 00 00 00 e5 00 00 00 d6 00 00 00 c4 00 00 00 c5 00
00 00 20 00 00 00 74 00 00 00 65 00 00 00 73 00 00 00 74 00 00 00 69 00 00 00 0a
00 00 00 00
===
Tämä on öäåÖÄÅ testi
Tämä on öäåÖÄÅ testi
===
0: Success
Testi
Tämä on öäåÖÄÅ testi
1: Illegal seek
2: Success
-------------------------------finish
Where
0: Success
Testi
Tämä on öäåÖÄÅ testi
should match
Tämä on öäåÖÄÅ testi
but does not.
The wofstream bits, do, indeed, work as expected.
-benjamin
--
Summary: UTF-8 encoding, wcout vs. file
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bkoz at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14623
- Follow-Ups:
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: pcarlini at suse dot de
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: pinskia at gcc dot gnu dot org
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: pcarlini at suse dot de
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: peturr02 at ru dot is
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: pcarlini at suse dot de
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: peturr02 at ru dot is
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: peturr02 at ru dot is
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: pcarlini at suse dot de
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: bkoz at redhat dot com
- [Bug libstdc++/14623] UTF-8 encoding, wcout vs. file
- From: pcarlini at suse dot de