I do not understand what you are saying about. Assigning zero to an integer number as for example defined by you int cur_char; sets all its bytes to 0.
But when you output this number in a text stream it are stored as one character equal to '0'.
Use the proper data type, and that would be char or wchar_t if you are using wide characters. To be more specific: Make cur_char of type char. That should work. If it doesn't, then open the file in binary mode.
The stream inserter by default will write your numeric data into ASCII format for human readability. So, when the integer value 0 is to be written to cout, cin, a file, etc., it will be written as the character '0', which is ASCII character 48 (hex 30).
As Texan40 said, if you want the binary value written to the file, you need to use the binary flag.
#include <iostream>
#include <fstream>
#include <cstdlib>
using std::ios_base;
using std::cout;
using std::cin;
using std::endl;
int main( )
{
int cur_char; // current character to write
std::ofstream fout("test.bin", ios_base::out | ios_base::binary | ios_base::trunc);
if (fout.bad( )) {
(std::cerr << "Can not open output file\n");
exit (8);
}
cur_char = 0; {
fout << cur_char;
}
return (0);
}