最近再写一个大文件的发送和接收,在发送安装包时,发送的文件属性里的大小与客户端接收到的属性大小不一样,因此写了一个二进制文件进行验证是哪里发送时出现了错误。
#include
#include
#include
using namespace std;
int main()
{
ofstream outfile; //也可以使用fstream, 但是fstream的默认打开方式不截断文件长度
// ofstream的默认打开方式是, 截断式写入 ios::out | ios::trunc
// fstream的默认打开方式是, 截断式写入 ios::out
// 建议指定打开方式
outfile.open("user.txt", ios::out | ios::trunc);
for (int num = 0; num < 10000; num++) {
outfile << bitset<10>(num);//10是二进制位数,自定义为多少输出就是多少位,高位补0
}
// 关闭打开的文件
outfile.close();
}



