PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > wifstream & locale
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
wifstream & locale

Réponse
 
LinkBack Outils de la discussion
Vieux 05/02/2008, 13h53   #1
koara
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut wifstream & locale

Hello all,

I needed to read contents of an UTF8 encoded file in C++ (gcc version
3.3.5 on Linux). I decided to do it the C++ way, using streams:

-------------
std::locale utf8loc("en_US.utf8");
std::wifstream ifs("smthg");
ifs.imbue(utf8loc);
std::wstring item;

while (ifs >> item) {
here
}

------------

but the inner block ("here") never gets executed. I tried searching
around the web and my head spins, surely doing such mundane,
straightforward task cannot be that complicated in C++? What am I
doing wrong please? What should I test for, look out for?

Cheers.

To narrow down my problem:
* I don't want to use any non-standard functions, libraries etc.
* the input file is in UTF8, I want to read (parts of) its contents as
wstring

---------------
$ locale -a
C
POSIX
en_GB.utf8
en_US.utf8
  Réponse avec citation
Vieux 05/02/2008, 17h15   #2
Christopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: wifstream & locale

On Feb 5, 7:53 am, koara <ko...@atlas.cz> wrote:
> Hello all,
>
> I needed to read contents of an UTF8 encoded file in C++ (gcc version
> 3.3.5 on Linux). I decided to do it the C++ way, using streams:
>
> -------------
> std::locale utf8loc("en_US.utf8");
> std::wifstream ifs("smthg");
> ifs.imbue(utf8loc);
> std::wstring item;
>
> while (ifs >> item) {
> here
> }
>
> ------------
>
> but the inner block ("here") never gets executed. I tried searching
> around the web and my head spins, surely doing such mundane,
> straightforward task cannot be that complicated in C++? What am I
> doing wrong please? What should I test for, look out for?
>
> Cheers.
>
> To narrow down my problem:
> * I don't want to use any non-standard functions, libraries etc.
> * the input file is in UTF8, I want to read (parts of) its contents as
> wstring
>
> ---------------
> $ locale -a
> C
> POSIX
> en_GB.utf8
> en_US.utf8


Mayhaps the file "smthg" does not contain text that is convertable to
a wstring? or no text at all?
What's in the file? Also did you ever check if it actually got opened?
Is it in the proper directory?

  Réponse avec citation
Vieux 06/02/2008, 13h33   #3
koara
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: wifstream & locale

On Feb 5, 5:15 pm, Christopher <cp...@austin.rr.com> wrote:

> Mayhaps the file "smthg" does not contain text that is convertable to
> a wstring?


No. It contains text convertible to wstring.

> What's in the file? Also did you ever check if it actually got opened?


Yes I did, problem is not in file opening.
File contains text with national characters (cz, de).

Cheers.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h08.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09555 seconds with 11 queries