Question about Extended ASCII character set, and fstream

G

Guest

Hey all,

Quick question...been bugging me for some time, really. I have a console app, it does some things, and I want to save an array of text to a text file. The text consists of ASCII and extended ascii (codes 0 to 255). I am using ofstream to output, and this is the line doing the actual output:

outfile << screenbuffer.Char.AsciiChar;

Note that screenbuffer is an array of type 'CHAR_INFO', quick info of it here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/char_info_str.asp

Anyhow, the output, when I open it up in Notepad, shows ASCII characters fine, but nothing from the extended set (the extened set characters are garbled... into other characters.) When I put some extended ASCII chars into notepad (by holding ALT and pressing some numbers), they appear ok. When I try to save the file, it tells me I need to save in Unicode format.

SOOOO, I cannot figure out how to output to a text file in Unicode format from my program. Any ideas?


Thanks in advance!
Andy
 
C

Catalin Pitis

Hey all,

Quick question...been bugging me for some time, really. I have a console
app, it does some things, and I want to save an array of text to a text
file. The text consists of ASCII and extended ascii (codes 0 to 255). I am
using ofstream to output, and this is the line doing the actual output:

outfile << screenbuffer.Char.AsciiChar;

Note that screenbuffer is an array of type 'CHAR_INFO', quick info of it
here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/char_info_str.asp

Anyhow, the output, when I open it up in Notepad, shows ASCII characters
fine, but nothing from the extended set (the extened set characters are
garbled... into other characters.) When I put some extended ASCII chars
into notepad (by holding ALT and pressing some numbers), they appear ok.
When I try to save the file, it tells me I need to save in Unicode format.

SOOOO, I cannot figure out how to output to a text file in Unicode format
from my program. Any ideas?

You have two choices:

1. Use wide char streams (std::wofstream)

or

2. Use unformatted output (basic_ostream<...>::write method)

Br/
Catalin
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top