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 6 7 8 // An example of setting and reading some bits. Note that operator[] 9 // goes from the least-significant bit at 0 to the most significant 10 // bit at size()-1. The operator<< for dynamic_bitset prints the 11 // bitset from most-significant to least-significant, since that is 12 // the format most people are used to reading. 13 // 14 // The output is: 15 // 16 // 11001 17 // 10011 18 // --------------------------------------------------------------------- 19 20 #include <iostream> 21 #include <boost/dynamic_bitset.hpp> 22 main()23int main() 24 { 25 boost::dynamic_bitset<> x(5); // all 0's by default 26 x[0] = 1; 27 x[1] = 1; 28 x[4] = 1; 29 for (boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i) 30 std::cout << x[i]; 31 std::cout << "\n"; 32 std::cout << x << "\n"; 33 34 return 0; 35 } 36