Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > wifstream & locale

Reply
Thread Tools

wifstream & locale

 
 
koara
Guest
Posts: n/a
 
      02-05-2008
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
 
Reply With Quote
 
 
 
 
Christopher
Guest
Posts: n/a
 
      02-05-2008
On Feb 5, 7:53 am, koara <(E-Mail Removed)> 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?

 
Reply With Quote
 
 
 
 
koara
Guest
Posts: n/a
 
      02-06-2008
On Feb 5, 5:15 pm, Christopher <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wifstream/wofstream names Ioannis Vranos C++ 1 09-30-2008 07:48 PM
wstring & wifstream toton C++ 9 10-02-2006 04:20 AM
Reading unicode (utf-16 le) using wifstream anubis C++ 2 03-21-2006 01:39 PM
ifstream and wifstream - combined Ben Hetland C++ 0 09-20-2005 01:55 PM
i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry Maurice Hulsman Java 1 07-25-2004 06:11 PM



Advertisments