0

So, the documentation says this:

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)

Effects: Inserts a textual representation of b into the stream os (highest bit first). Informally, the output is the same as doing

std::basic_string<Char, Traits> s;
boost::to_string(x, s):
os << s;

which I don't understand at all.

Here is what I have

boost::dynamic_bitset<> bit_value(Config::HASH_WIDTH_IN_BITS, hash_value);
string buffer = bit_value.to_string();

Which doesn't work, cause dynamic bitset has no member .to_string();

1 Answer 1

8

to_string is a free function in the boost namespace, not a member function.

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.
Sign up to request clarification or add additional context in comments.

2 Comments

Which header should be included?
boost::dynamic_bitset is defined in boost/dynamic_bitset.hpp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.