473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3908
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
0
by: Sarah Akers | last post by:
GgF ----gL5cJ72EqiGIQ0SK65Rz Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html> <head> <style type=3D"text/css">.eyebrow { FONT-WEIGHT: bold; FONT-SIZE: 10px; TE=
0
by: Blake Mandelbaum | last post by:
bgc ----mDuNni7bWv1kUF0gGK Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html><head><style type=3Dtext/css>.eyebrow { FONT-WEIGHT: bold; FONT-SIZE= : 10px;...
1
by: Manolatos Tilemahos | last post by:
Dear friends, First pls accept my apologies, because I am a new Postgres user, so my questions could be silly. We need to setup a database using UTF-8 encoding, however, by some way, we have...
2
by: anubis | last post by:
Heay, i've got this problem: http://rafb.net/paste/results/lpNgbn49.html i'm using wifstream to read utf-16 file and i've got this problem, that each byte is read into seperate char while...
7
by: Niels | last post by:
Whenever I enter a line with spaces in a cin >> .. line my program seems to skip all cin lines after that point. Could someone please explain me why this is? I'm calling this procedure from main,...
9
by: toton | last post by:
Hi, I have my program using wstring everywhere instead of string. Similarly I need to process some file, which contains unicode or ascii character. I need to stream them. Thus I use wifstream etc....
13
by: Soumen | last post by:
I wanted convert a mixed case string to a lower case one. And I tried following code: std::transform(mixedCaseString.begin(), mixedCaseString::end(), mixedCaseString.begin(),...
2
by: mathieu | last post by:
Hi, I am playing with the following C++ piece of code (*). At least on my system debian/gcc 4.3 it looks like I am not writing out a floating point separator as a comma. what are the operation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.