Binary I/O

This is a discussion on Binary I/O within the C++ Programming forums, part of the General Programming Boards category; How do you write and/or read a character array to a file using a binary file stream. Thank you....

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    23

    Binary I/O

    How do you write and/or read a character array to a file using a binary file stream. Thank you.

  2. #2
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    As I said, all your records must be the same length. But lets say the only thing you want to write is an array of characters that is 20 characters long.

    char array[20];

    memset(array,0,sizeof(array));

    strcpy(array,"IfYouSaySo");

    ofstream of;

    of.open("file.dat", ios_base:ut, ios_base::binary);

    // if you wanted to write to a different offset than 0, use
    // seekp member:
    // of.seekp( sizeof(array) * 3, ios_base::beg );

    of.write(array, sizeof(array));

    of.close();
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary I/O with cin and cout
    By The Urchin in forum C++ Programming
    Replies: 4
    Last Post: 10-24-2006, 12:47 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Binary File I/O
    By sean in forum C Programming
    Replies: 7
    Last Post: 08-20-2004, 10:56 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 04:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21