#include // std::bitset
int main ()
{
std::bitset<4> mybits; // mybits: 0000
mybits.set(); // mybits: 1111
std::string mystring =
mybits.to_string<char,std::string::traits_type,std::string::allocator_type>();
std::cout << "mystring: " << mystring << '\n';
return 0;
}4>
------------
std::bitset<8> foo (std::string("10110011"));
std::cout << foo << " has ";
std::cout << foo.count() << " ones and ";
std::cout << (foo.size()-foo.count()) << " zeros.\n";
8>
-------------------
std::cout << foo.set() << '\n'; // 1111
std::cout << foo.set(2,0) << '\n'; // 1011
std::cout << foo.set(2) << '\n'; // 1111
------------
std::bitset<4> foo (std::string("1011"));
std::cout << foo.reset(1) << '\n'; // 10014>
---------------
No comments:
Post a Comment