Thread: Making Binary Output to files using VC++ 6's "fstream"

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    70

    Question Making Binary Output to files using VC++ 6's "fstream"

    Hey,

    How can i make Non-ASCII (Binary) Output to files using MSC++ 6's File Stream Classes??

    I Hope my Question is Clear

    Cya.

  2. #2
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    Code:
    int n=800;
    ostream out("file",ios :: binary|ios :: out)
    out.write((char *) &n,sizeof n);
    I think
    Last edited by Panopticon; 02-03-2003 at 11:15 PM.
    I AM WINNER!!!1!111oneoneomne

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    This Doesn't seem to work, Does somebody else know how to do this??

  4. #4
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    It should work. I had a typo before, forgot to end the declaration with a semicolon.
    I AM WINNER!!!1!111oneoneomne

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    I'm sorry, but it doesn't work. I noticed the Semi-Colon Error Before, i fixed this before even using the Code.

    Is there another way??

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    There are many different ways, but if you tell us what exactly "doesn't work" we could help you fix this one.

    int n=800;
    ofstream out;
    out.open( "filename", ios::binary );
    if( out.fail() ) // do something, file not opened
    out.write( &n, sizeof( n ) );
    out.close();


    http://www.cplusplus.com/ref/iostrea...eam/write.html
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  2. Binary files
    By Lionmane in forum C Programming
    Replies: 35
    Last Post: 08-25-2005, 01:56 PM
  3. Reading Binary files
    By earth_angel in forum C++ Programming
    Replies: 10
    Last Post: 07-12-2005, 06:48 AM
  4. Specifying binary output?
    By Hardboy in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2003, 03:41 PM
  5. Reading binary files and writing as text
    By thenrkst in forum C++ Programming
    Replies: 8
    Last Post: 03-13-2003, 10:47 PM