How can I look at the primitive binary of a file, and change it?

I can't figure out how to dismantle a file and see its binary.

Page 1 of 1

1 Replies - 615 Views - Last Post: 04 April 2009 - 02:55 AM Rate Topic: -----

#1 Hermitpenguin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-April 09

How can I look at the primitive binary of a file, and change it?

Posted 04 April 2009 - 02:21 AM

Hello everyone, I was wondering how I can look at a files binary through the use of C++, and also edit it. I'm a beginner to C++, but its hanging with me pretty easy.

I need to be able to edit the file's binary also, but I cant figure out how to do that. I'm creating a simple encrypting program that will rearrange the binary. If that is not possible, is there a way to mix up sectors of a file?

Any help would be greatly appreciated :)

This post has been edited by Hermitpenguin: 04 April 2009 - 02:22 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How can I look at the primitive binary of a file, and change it?

#2 rs4  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 153
  • Joined: 01-February 09

Re: How can I look at the primitive binary of a file, and change it?

Posted 04 April 2009 - 02:55 AM

Yes you can do so by using the file streams included in the fstream header.

In the following you enter name as the name you wish to refer to the stream as.
ifstream name(file name,ios::binary);//Read from file
ofstream name(file name,ios::binary);//Write to file
fstream name(file name,ios::binary);//Read and write from/to file

You can test if the file has been opened successfully like this
if(!name){
cout<<"error cannot open file";
return 1;
}

To read from a file use name.get(x) were x is the char varible which the value will be put into
To write use name.put(x);
These work sequantually, the 1st time you run one it will get the 1st char in the file, 2nd time 2nd char and so on. This is a very quick overview heres a good book read chapter 11 for more file operations C++ Beginner's Guide.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1