Thread: Specifying binary output?

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

    Specifying binary output?

    Hi,

    I´ve made a program which should output som binary data. The problem is that more bytes than I specify gets out, and somehow the data seems a little corrupt. It´s only a problem under Windows, so I´ll guess it´s because there is some translation of bytes in the run. The code is:
    Code:
    bool ppmImage::WriteRaw(ostream& out){
    	int size;
    	if((width==0)&&(height==0)){return false;}
    	size=width;
    	size*=height;
    	size*=3;
    	out.write((const char*) data_p,size);
    	return true;
    }
    Is there a way I can specify, that output should be considered binary, like:
    Code:
    out.settype(BINARY);
    or an equivalent function??

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Use "ios::binary" in the mode when you open the file. It will be ignored on other OS's that don't do newline translations.

    gg

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    29
    And what if it is standard output? How do I specify "cout" to be binary?

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You will have to use setmode() on stdout. This is Windows specific so....

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting 32 bit binary IP to decimal IP (vice-versa)
    By Mankthetank19 in forum C Programming
    Replies: 15
    Last Post: 12-28-2009, 07:17 PM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. why this output?
    By dredre in forum C Programming
    Replies: 4
    Last Post: 05-08-2004, 04:09 PM
  4. Binary Output
    By Ajsan in forum C++ Programming
    Replies: 9
    Last Post: 04-23-2004, 04:43 PM
  5. Array, Linked List, or Binary Tree?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 01-05-2002, 10:07 PM