Question about Extended ASCII character set, and fstream

Discussion in 'C++' started by Guest, Oct 21, 2004.

  1. Guest

    Guest 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
    Guest, Oct 21, 2004
    #1
    1. Advertising

  2. <> wrote in message news:...
    > 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
    Catalin Pitis, Oct 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Armando
    Replies:
    6
    Views:
    735
    Armando
    Jan 29, 2004
  2. Guest
    Replies:
    1
    Views:
    466
    Ron Natalie
    Oct 21, 2004
  3. John Gregory
    Replies:
    0
    Views:
    278
    John Gregory
    Jul 5, 2009
  4. Don Norcott

    Extended ASCII character handeling

    Don Norcott, Nov 17, 2010, in forum: Ruby
    Replies:
    3
    Views:
    342
    Brian Candler
    Nov 18, 2010
  5. James O'Brien
    Replies:
    3
    Views:
    234
    Ben Morrow
    Mar 5, 2004
Loading...

Share This Page