LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-01-2009, 12:13 PM   #1
matiasar
Member
 
Registered: Nov 2006
Location: Argentina
Distribution: Debian
Posts: 273
Blog Entries: 1

Rep: Reputation: 30
C++: force ofstream to create file with iso-8859-1 encoding


Hello all,

I did a program that makes some txt files using ofstream class. The problem I found is that despite my linux box is set to ISO-8859-1 the output txt files that the program creates are unicode UTF-8:

Quote:
output_file.txt: UTF-8 Unicode text
My box's locale

Quote:
LANG=es_AR.ISO-8859-1
LC_CTYPE="es_AR.ISO-8859-1"
LC_NUMERIC="es_AR.ISO-8859-1"
LC_TIME="es_AR.ISO-8859-1"
LC_COLLATE="es_AR.ISO-8859-1"
LC_MONETARY="es_AR.ISO-8859-1"
LC_MESSAGES="es_AR.ISO-8859-1"
LC_PAPER="es_AR.ISO-8859-1"
LC_NAME="es_AR.ISO-8859-1"
LC_ADDRESS="es_AR.ISO-8859-1"
LC_TELEPHONE="es_AR.ISO-8859-1"
LC_MEASUREMENT="es_AR.ISO-8859-1"
LC_IDENTIFICATION="es_AR.ISO-8859-1"
LC_ALL=

Does anybody knows how I can force ofstream class to use ISO-8859-1 encoding?
I'm using Fedora Core 9.


Tnanks in advance,
Matías
 
Old 04-01-2009, 04:38 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: Slackware64 13.37, Kubuntu 10.04
Posts: 2,944

Rep: Reputation: Disabled
g++ probably compiles programs to use UTF-8 by default (that's probably how the distro maintainer compiled it.) You need to imbue the other locale within the program. Those env should only change how gcc reads the files and displays its own output.
Kevin Barry
 
Old 04-02-2009, 08:56 AM   #3
matiasar
Member
 
Registered: Nov 2006
Location: Argentina
Distribution: Debian
Posts: 273
Blog Entries: 1

Original Poster
Rep: Reputation: 30
ta0kira, thanks for your reply!
Yes, I used locale library and imbue, but my output files continued to be utf-8. Previously I had set my box to used utf-8 so I found my sources (.cpp) continued to be encoded with utf-8. I used iconv to convert them and then compilled again, including locale and imbue, and with all sources in iso-8859-1 then it worked.

Thank you for the help,
Matías
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert file from ISO-8859-1 to some Japanese encoding? (iconv errors) violagirl23 Linux - Software 5 03-26-2008 12:13 AM
convert text-file from utf-8 to iso-8859-1 [SOLVED] @ngelot Linux - Server 1 06-12-2007 05:47 AM
How to create a header file in Unicode codepage -1200 Encoding in linux Mini Singh Linux - General 0 05-25-2007 08:10 AM
Changing system character encoding to ISO 8859-1 flork Suse/Novell 1 12-15-2005 06:21 AM
iso 8859 or iso 9960 tsundram Linux - Newbie 16 02-22-2002 10:32 PM


All times are GMT -5. The time now is 03:06 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration