📄 e04-04.cpp
字号:
// =======================================================
// Chapter 4, Example 1
// The Bitvector Class
// =======================================================
#include "Bitvector.h"
void main()
{
// create a bitvector with 32 bits.
Bitvector bitv( 32 );
bool b;
// set index 0 to true, and retrieve it again.
bitv.Set( 0, true );
b = bitv[0];
// set index 31 to false, and retrieve it again.
bitv.Set( 31, false );
b = bitv[31];
// set all the bits in the vector to 0
bitv.ClearAll();
// set all the bits in the vector to 1
bitv.SetAll();
// resize the bitvector to 48 bits
bitv.Resize( 48 );
// get the size of the bitvector.
int s = bitv.Size();
// Why is s = 64? Remember, since we are on a 32 bit system,
// we can only have multiples of 32. Since we asked for 48
// bits, the resize algorithm had to make enough room for 48 bits,
// so it jumped up to the next level and made 64.
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -