473,722 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(utf8l oc);
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 3921
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(utf8l oc);
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.r r.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
8227
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 not - be able to use non-ASCII characters in strings and in Tk GUI button labels and GUI window titles and in raw_input data without Python returning wrong case in manipulated
0
1936
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
1643
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; TEXT-TRANSFORM: uppercase; COLOR: #ffffff; FONT-FAMILY: verdana,ar= ial,helvetica,sans-serif; TEXT-DECORATION: none } A.eyebrow:link { TEXT-DE= CORATION: none }</style><title>V</title><meta http-equiv=3DContent-Type co=
1
3222
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 to express our need for right Greek character collation order. I tried the default installation using pginstaller, then I created a db (using pgAdminIII) using UTF-8, but still the collation is wrong (=wrong upper() and "order by") for Greek...
2
8797
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 little-endian uses at least 2 bytes for one sign. the code of method is in the above letter, also with the problem i'm attaching below:
7
3139
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, to enter certain data about a product: Product* getData() { // Create new item Product* pProd = new Product;
9
9613
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. However the open member function of is not templated, and use const char* as filename. I have my filename as wstring, where c_str() returns const wchar_t* type. Thus how to convert a wstring to string or const char* and pass to open of wifstream?
13
2993
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(), std::ptr_fun(tolower)); Even though I's including cctype and algorithm, I's getting compiler (g ++ 3.3.6) error: no matching function for call to `ptr_fun(<unknown type>)'
2
5308
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 affected by the LC_NUMERIC env var value ? Thanks -Mathieu
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.