使用std::bitset生成二进制文件
Use std::bitset to produce binary file
我使用std::bitset
来给我一个数字的二进制表示。我现在想使用它,并只使用二进制表示输出到std::cout
-我不想使用std::bitset
的ASCII表示-我只想输出我在内存中的位集。
bitset<32> bits = a;
cout << bits; //produces the ASCII characters for '1' and '0' depending on a
如果您的位集在函数to_ulong
或to_ullong
的限制范围内,则可以使用这些函数并将其直接输出到二进制文件中。
如果您的位集超过了unsigned long
或unsigned long long
可以存储的量,则函数将引发溢出异常。这意味着您需要提取位集的子集,并为每个子集将unsigned long
或unsigned long long
存储到文件中。
不幸的是,std::bitset
没有提供直接的子集函数,所以您必须自己编写。
相关文章:
- 正在读取二进制文件(is_open)
- 在C++中将类(带有Vector成员)保存为二进制文件
- 如何从二进制文件中读取字符串
- 保存/加载大量短数组到二进制文件
- 从二进制文件中读取整数数组
- Android 在编译二进制文件时重建静态库
- 在 C++ 中将双精度变量写入二进制文件
- clang 的 libFuzzer 可以在同一二进制文件中测试超过 1 个 API 吗?
- C++:实际上不是从二进制文件中读取
- 如何从二进制文件中的给定符号中获取调用程序图
- 将内部带有矢量的结构保存/读取到二进制文件中
- 编译多个C++文件.调用二进制文件以运行代码
- 如何使用位字段将数据从二进制文件复制到结构中?
- uint8_t同一二进制文件的不同十进制值
- C++单个生成文件多个二进制文件
- 尝试将数字写入二进制文件时引发异常
- C++中读/写二进制文件
- 如何在 c++ 中将二进制文件加载/读取到"vector<vector< bitset<32> >"中?
- 使用std::bitset生成二进制文件
- 将std::bitset写入二进制文件,然后将文件加载到std:bitset