Is it talking about using cin and cout like cin>>x, cout<<x so that it outputs in binary instead of ASCII text?
Because my understanding is that write() and read() can do the job.
It depends on what you mean by "binary".
If you are talking about base-2, then you can use strtol() to convert a string of ASCII ones & zeros to a long int. (Actually, strtol() can convert any base from base-2 to base-36.)
Code:
const int MAX_BITS = 8; // Limit to one-byte to make binary readable
int Base, x;
char InputString[40];
char *pEnd = NULL; // Required for Strtol()
cout << "Base? (2-36, 0 to exit) " ;
cin >> Base;
cout << "Number? "
cin >> InputString; // C-Style null-terminated string
x = (int)strtol(InputString, &pEnd, Base); // String to long (typecast to int)
And, you can use <bitset> with cout to display a number in binary (base-2).
Code:
cout << "\t" << dec << x << "\t\t Decimal" << endl;
cout << "\t" << oct << x << "\t\t Octal" << endl;
cout << "\t" << hex << x << "\t\t Hex" << endl;
cout << "\t" << bitset<MAX_BITS>(x) << "\t Binary (LSB)" << endl;
When you read & write a file in "binary", this does not mean base-2! It means "raw" or "unaltered", as contrasted with the "text" mode which formats text with carraige return and/or linefeed as required for text files on your system.