I have a string in char a[100]=00110010
which is the ascii code of '2'.

Now i want to write this in a text (or binary) file as binary bits.
So that when i open the file in binary mode and read a character char ch
say via

ifstream fin;

and then


output should be '2' only.

Another question?
Since 'a' is 101 byte array, would

ofstream fout;

this code will write 101 characters in the file or only 8 characters?

I didn't understand clearly what do you mean, but i'll explain what I know:

a[100] is an array containing 100 chars, each char represents a byte, then the array is a 100 Byte array.
to read an write in binary ifstream has function called read, and ofstream has one called write.