Thread: Writing to "binary" files

  1. #1
    Registered User
    Join Date
    Nov 2001

    Writing to "binary" files


    Just a question on the code i've posted below.

    It writes to the file out.bin but when i view it (thru notepad or edit or whatever) i can see the word "HELLO".

    If this is a "binary" file should i be able to see the characters like that? I thought i mite get the bit equivalents.....

    #include <iostream>
    #include <fstream>
    using namespace std;
    int main()
    	ofstream outFile;
    	char file[8] = "out.bin";
    	char buffer[10] = "HELLO";
, ios::out | ios::binary);
    	outFile.write (reinterpret_cast< const char* >(buffer), 5);
    	return 0;
    Cheers gang.


  2. #2
    Join Date
    Sep 2003
    Binary means that you are writing bytes, nothing more. Indeed, you are writing the bytes, but notepad just make an interpretation of them, making them letters where they wre letters and unreadable else.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with writing to files
    By beanroaster in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2007, 12:21 AM
  2. Reading & Writing files (Error)
    By Blackroot in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2006, 11:55 AM
  3. Writing files to a CD
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 04-16-2003, 04:43 PM
  4. *.COM Files? Writing them?
    By johnc in forum A Brief History of
    Replies: 13
    Last Post: 07-11-2002, 01:52 AM
  5. Making files, opening them, and writing to them
    By Unregistered in forum Game Programming
    Replies: 6
    Last Post: 06-18-2002, 09:57 PM