LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to open file in binary mode (https://www.linuxquestions.org/questions/programming-9/how-to-open-file-in-binary-mode-573572/)

amit_pansuria 07-31-2007 12:30 AM

how to open file in binary mode
 
helo,
i m using fedora 6 .
i m writing my application using c,c++
how can i open any file in binary format
Regards,
Amit

Nylex 07-31-2007 12:33 AM

In C++, you use "ios::binary" as the second argument to your ifstream/ofstream constructor:

ifstream in("foo", ios::binary);
ofstream out("foo", ios::binary);

Not sure about C.

bigearsbilly 07-31-2007 02:49 AM

files as a binary concept belongs to those inferior O.S's.
there is no binary and ASCII under unix like systems.

Nylex 07-31-2007 03:15 AM

Eh? Why not? :confused:

bigearsbilly 07-31-2007 03:31 AM

well, in DOS you have ascii and binary, so in ascii if you write a
file it will translate a "\n" to a "\r\n"

while in unix a "\n" is a "\n", a file is a file is a file.


like the ASCII and binary mode for ftp, if you mix it up on DOS it
messes the file up but in unix it doesn't care.

another wondeful legacy from mr Gates' crap programming, as well as enabling the internet to fill up with viruses, spam and botnets ;)


All times are GMT -5. The time now is 06:32 PM.