-
file IO problem
hello
in my program, i want to be able to read, and write the binary values. i want to be able to read: (as text) "hi", and getr (in hex) "68 69",
then i want to be able to write (as hex) "FF FF" and stuff.
in short i want to need to use a hex editor to view my values,
here is what i got so far
Code:
unsigned encrypt2bytes(unsigned key){
ifstream qaz("data.txt",ios::in | ios::binary ); // this file is just opened to
if (! qaz){ cout << "error, check file existance";} // to let us read it
unsigned tev; qaz>> tev;
ofstream qaze("endata.txt", ios::binary | ios::out); //this is the one that actually is going to write to the new file
if (! qaze){ cout << "error, check file existance";}
qaze << encrypt(key, tev);
qaz.close();
qaze.close();
return 0;
}
unsigned decrypt2bytes(unsigned key){
ifstream qaz("endata.txt", ios::in | ios::binary); // this file is just opened to
if (! qaz){ cout << "error, check file existance";} // to let us read it
unsigned tev; qaz >> tev;
ofstream qaze("data.txt", ios::binary | ios::out); //this is the one that actually is going to write to the new file
if (! qaze){ cout << "error, check file existance";}
qaze << decrypt(key, tev);
qaz.close();
qaze.close();
return 0;
}
thanks
-
The data in the file is binary in any case, as is everything in the computer. How you actually see it is only a matter of the program you use to view it. If you open an exe file in notepad you'll see some strings embedded in it. If you open a text file in a hex editor you see the hex values. If you open a specially treated gif file in an image viewer you see a dinosaur. If you open it with winzip you can extract the DeCSS source code from it.
It's all a matter of interpretation.
-
To read a binary file you could get some hex dump utility (download off the internet). Or you can simply open the file in VC++ 6.0, won't work for VC++ .NET (or probably you have to go though some steps that I don't know of)
-
It works. You have to add it as a custom resource to some dummy project though.