example1.cpp 963 B

1234567891011121314151617181920212223242526272829303132333435
  1. // (C) Copyright Jeremy Siek 2001.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // An example of setting and reading some bits. Note that operator[]
  6. // goes from the least-significant bit at 0 to the most significant
  7. // bit at size()-1. The operator<< for dynamic_bitset prints the
  8. // bitset from most-significant to least-significant, since that is
  9. // the format most people are used to reading.
  10. //
  11. // The output is:
  12. //
  13. // 11001
  14. // 10011
  15. // ---------------------------------------------------------------------
  16. #include <iostream>
  17. #include <boost/dynamic_bitset.hpp>
  18. int main()
  19. {
  20. boost::dynamic_bitset<> x(5); // all 0's by default
  21. x[0] = 1;
  22. x[1] = 1;
  23. x[4] = 1;
  24. for (boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i)
  25. std::cout << x[i];
  26. std::cout << "\n";
  27. std::cout << x << "\n";
  28. return 0;
  29. }