Is it possible to open a file in binary mode and make an array out of it then to encrypt that information. I guess I should ask how you would start something like that? Thanks

Recommended Answers

All 6 Replies

Well your question is not quite clear but you can always use fopen command with :
“rb” Open a binary file for reading
“wb” Create a binary file for writing
“ab” Append to a binary file
“rb+“ Open a binary file for read/write
“wb+“ Create a binary file for read/write
“ab+“ Open a binary file for read/write

as modes to manipulate it.For more info try this.

This helps, but to clarify, instead of taking a string of charecters from a text file and throwing them into an array, is it possible to take that same concept but do it with binary? Thanks

Well if you are using linux then you can always use the meta-characters and the od command to your requirements.Check these out <1> <2>

Yes, of course it can be done. Same as text.

commented: you follow two specific and helpful comments with this? and then complain about me? LOL :P -2

>This helps, but to clarify, instead of taking a string of charecters from a text file and throwing
>them into an array, is it possible to take that same concept but do it with binary? Thanks

Yes, but don't expect that you would be able to display them. A binary file is a stream of unformatted character. That is, it is raw and does not follow ASCII standards. Hence your terminal won't be able to display it. But it sure can be dumped into a char array.

fstream f("asdf.dat");
char* arr=new char[ sizeof file];
f.read(reinterpret_cast<char*>(arr), size of file);
char* arr = new char[...];
f.read(reinterpret_cast<char*>(arr), ...

Why reinterpret_cast?..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.