c++二进制文件

建立某单位职工通信录二进制文件,文件中的每个记录包括职工编号,姓名,电话号码,邮政编码和住址。
我问一下,二进制文件怎么输出啊?
我写了个程序
#include <iostream.h>
#include <fstream.h>
#include <string.h>
main()
{char b,a;
fstream file("D:\\5.txt",ios::out|ios::in|ios::binary);
cin>>&b;
file.write(&b,sizeof(char));
long posend=file.tellg();
file.seekp(0,ios::beg);
file.seekg(0,ios::beg);
file.read(&a,sizeof(char));
cout<<&a+1<<',';
cout<<posend<<file.tellg()<<endl;
file.close();
}

文件流重载了操作符号<<和>>的,
你直接file<<或者file>>就可以了
你输出到屏幕的话,读一个字符输出1个:

char buf = '\0';
//每次读取一个字符
while (!file.eof())
{
file>>buf;
std::cout<<(buf);
}
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜