C++和Boost:如何将动态位集转换为字符串?

Nul*_*uli 0 c++ boost

所以,文档说这个:

template <typename Char, typename Traits, typename Block, typename Alloc>
basic_ostream<Char, Traits>&
operator<<(basic_ostream<Char, Traits>& os, const dynamic_bitset<Block, Alloc>& b)
Run Code Online (Sandbox Code Playgroud)

效果:将b的文本表示插入到流os中(最高位为第一位).非正式地,输出与执行相同

std::basic_string<Char, Traits> s;
boost::to_string(x, s):
os << s;
Run Code Online (Sandbox Code Playgroud)

我根本不明白.

这就是我所拥有的

boost::dynamic_bitset<> bit_value(Config::HASH_WIDTH_IN_BITS, hash_value);
string buffer = bit_value.to_string();
Run Code Online (Sandbox Code Playgroud)

哪个不起作用,导致动态bitset没有成员.to_string();

dal*_*lle 6

to_stringboost命名空间中的自由函数,而不是成员函数.

boost::dynamic_bitset<> bit_value(Config::HASH_WIDTH_IN_BITS, hash_value);
string buffer;
to_string(bit_value, buffer);
// here buffer contains the string representation of bit_value.
Run Code Online (Sandbox Code Playgroud)