Thread: I/O to binary file

  1. #1
    Registered User
    Join Date
    Oct 2001

    I/O to binary file

    char name[61];
    char director[31];
    char cast[156];
    short int duration,

    This will add up to 256 bytes so the recordset is 256 in the binary
    when the program starts it opens the binary file it it has to read all the records into a dynamic string.

    ifstream infile("m.dat", ios::in | ios:ut | ios::binary);

    infile.seekg(0, ios::end);
    fsize = infile.tellg();
    infile.seekg(0, ios::beg);
    current = new char[fsize];

    my problem is that when i copy the records into the string it will not hold the spaces.
    What i mean is if the first ten spaces in name from binary has "jjjjjjjjjj" and the rest of the 51 spaces are empty.
    i want the string current to hold "jjjjjjjjjj" + 51 spaces;
    How can i do that;

    this is a console app on win. using borland
    #include <iostream.h>
    void main(void){
    char t[7] = "Thanks";

    cout<< t <<endl;

  2. #2
    Registered User
    Join Date
    Oct 2001
    Did you use write() to write the records? Assuming you filled name with 10 characters + 50 spaces using strcpy() or at the declaration, when you read it back using it will contain the spaces.

    However there is only room for 50 spaces, not 51, as the string terminator takes one space.

  3. #3
    Registered User
    Join Date
    Aug 2001
    I'm having problems with files myself, but don't know if you can open an ifstream with ios:ut. Never seen it, anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  2. File I/O Question
    By Achy in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 AM
  3. Problem with Binary File I/O
    By DirX in forum C++ Programming
    Replies: 4
    Last Post: 03-01-2004, 09:34 AM
  4. Binary FIle I/O
    By MethodMan in forum C Programming
    Replies: 5
    Last Post: 03-21-2003, 02:22 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM