468,513 Members | 1,751 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

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
Feb 5 '08 #1
2 3416
On Feb 5, 7:53 am, koara <ko...@atlas.czwrote:
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?

Feb 5 '08 #2
On Feb 5, 5:15 pm, Christopher <cp...@austin.rr.comwrote:
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.
Feb 6 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by anubis | last post: by
7 posts views Thread by Niels | last post: by
9 posts views Thread by toton | last post: by
13 posts views Thread by Soumen | last post: by
2 posts views Thread by mathieu | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.