且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C ++中将二进制字符串输出到二进制文件

更新时间:2023-02-10 18:36:29

使用位集:

//Added extra leading zero to make 32-bit.
std::bitset<32> b("00110110101011110110010010000010");

auto ull = b.to_ullong();

std::ofstream f;
f.open("test_file.dat", std::ios_base::out | std::ios_base::binary);
f.write(reinterpret_cast<char*>(&ull), sizeof(ull));
f.close();