使用karma::big_word
orkarma::little_word
可能是一个选项:
在 Coliru上现场观看
输出/a.out && xxd this.raw
:
0000000: f000 f001 f002 f003 f004 f005 f006 f007 ................
0000010: f008 f009 f00a f00b f00c f00d f00e f00f ................
0000020: f010 f011 f012 f013 f014 f015 f016 f017 ................
0000030: f018 f019 f01a f01b f01c f01d f01e f01f ................
0000040: f020 f021 f022 f023 f024 f025 f026 f027 . .!.".#.$.%.&.'
// ...
0000200: 00f0 01f0 02f0 03f0 04f0 05f0 06f0 07f0 ................
0000210: 08f0 09f0 0af0 0bf0 0cf0 0df0 0ef0 0ff0 ................
0000220: 10f0 11f0 12f0 13f0 14f0 15f0 16f0 17f0 ................
0000230: 18f0 19f0 1af0 1bf0 1cf0 1df0 1ef0 1ff0 ................
0000240: 20f0 21f0 22f0 23f0 24f0 25f0 26f0 27f0 .!.".#.$.%.&.'.
完整代码:
#include <boost/spirit/include/karma.hpp>
#include <fstream>
namespace karma = boost::spirit::karma;
template <typename C>
void fillMyArray(C& data)
{
std::iota(begin(data), end(data), 0xf000);
}
int main()
{
std::vector<boost::uint32_t> data(256);
fillMyArray(data);
std::ofstream output( "this.raw", std::ios_base::out | std::ios_base::binary | std::ios_base::trunc );
boost::spirit::karma::ostream_iterator<char> outit(output);
karma::generate(outit, +karma::big_word, data);
karma::generate(outit, +karma::little_word, data);
}