65,208
社区成员
发帖
与我相关
我的任务
分享
bitset <5>b1( x ); //x= 0,1,2, ... ,31
bitset <5>b = b1;
#include "stdafx.h"
// bitset_reset.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
int main( )
{
using namespace std;
bitset<5> b1 ( 31);// 13 对应的2进制 ---是5位
cout << "The set of bits in bitset<5> b1(13) is: ( "<< b1 << " )"
<< endl;
bitset<5> b1r3;
b1r3 = b1.reset( 2 );// 把 第二位的数字改变 0变成 1 ,1变成0
cout << "The collecion of bits obtained from resetting the\n"
<< " third bit of bitset b1 is: ( "<< b1r3 << " )"
<< endl;
bitset<5> b1r;
b1r = b1.reset( );//全部置0
cout << "The collecion of bits obtained from resetting all\n"
<< " the elements of the bitset b1 is: ( "<< b1r << " )"
<< endl;
}
#include "stdafx.h"
// bitset_reset.cpp msdn上的例子
// compile with: /EHsc
#include <bitset>
#include <iostream>
int main( )
{
using namespace std;
bitset<32> b1 ( 13 );// 13 对应的2进制
cout << "The set of bits in bitset<5> b1(13) is: ( "<< b1 << " )"
<< endl;
bitset<32> b1r3;
b1r3 = b1.reset( 2 );// 把 第二位的数字改变 0变成 1 ,1变成0
cout << "The collecion of bits obtained from resetting the\n"
<< " third bit of bitset b1 is: ( "<< b1r3 << " )"
<< endl;
bitset<32> b1r;
b1r = b1.reset( );//全部置0
cout << "The collecion of bits obtained from resetting all\n"
<< " the elements of the bitset b1 is: ( "<< b1r << " )"
<< endl;
}