Thread: Binary files in C++

  1. #1
    Unregistered
    Guest

    Post Binary files in C++

    I'm curious as to whether there is a way of saving binary files using C++ rather than text files. I'm thinking of something along the line of:
    outbinfile << unique_variable;
    and then later unique_variable >> inbinfile;
    This way when you look at the file using a text editor it is just garbage. I know Java has this feature, is it possible with C++? I don't want to get into serialization in VC++. Any help or sample code would be greatly appreciated. Thanks.

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    i would open a file in binary mode using the ios::binary flag when opening it.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Unregistered
    Guest

    how do you read from a binary file

    Thanks, usually, when reading from a text file I use getline... what would you suggest for reading and skipping around inside a binary file?

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    i don't use ifstream to a great extent so i can only suggest what looks effective.

    but as i see it i would probably use read() and seekg() the majority of the time, as in C style File I/O.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  2. send/recv binary files using sockets in C++
    By dafatdude in forum Networking/Device Communication
    Replies: 14
    Last Post: 07-25-2004, 11:00 AM
  3. MFC: CStrings & binary files question(s)
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-24-2004, 05:41 PM
  4. Binary files
    By Brian in forum C Programming
    Replies: 2
    Last Post: 02-18-2002, 01:13 PM
  5. storing string objects to binary files
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-06-2001, 11:33 PM