Language support (UTF-8 with std::string and std::cout) help

J

James Vanns

I want to be able to print out (and read in) characters with accents
(for example French and Italian text). So far I have this:


std::locale lang (getenv ("LANG"));

which seems to set the locale correctly, say to it_IT.utf8 (on UNIX).

However, when reading in text from a file using:

std::string input;
std::copy (istream_iterator<char> (file), istream_iterator<char> (),
back_inserter (input));

and then using std::cout at certain subscripts or indicies within the
string the ones with accents appear like this:

<A0>
<A8>

etc.

What am I doing wrong? What to I need to do in order to process the
text correctly?

Thanks

James Vanns
 
P

P.J. Plauger

I want to be able to print out (and read in) characters with accents
(for example French and Italian text). So far I have this:


std::locale lang (getenv ("LANG"));

which seems to set the locale correctly, say to it_IT.utf8 (on UNIX).

However, when reading in text from a file using:

std::string input;
std::copy (istream_iterator<char> (file), istream_iterator<char> (),
back_inserter (input));

and then using std::cout at certain subscripts or indicies within the
string the ones with accents appear like this:

<A0>
<A8>

etc.

What am I doing wrong? What to I need to do in order to process the
text correctly?

Looks to me like you're getting one of the ISO-8859-x character
sets for your troubles. These are all 256-byte character sets that
give different meanings for different European cultures to the last
128 elements. If you want *that* converted to UTF-8, you need a
codecvt facet that will do the job. We have such a set of facets
in our CoreX library. If you don't want to walk that path, you've
got some information scrounging and code writing ahead of you.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top