bitset :: all()是C++ STL中的内置函数,如果所有位都以数字的二进制表示形式设置(如果在位集中进行了初始化),则该函数将返回True。如果未设置所有位,则返回False。
句法:
bool bitset_name.all()
参数:此函数不接受任何参数。
返回值:该函数返回一个布尔值。如果所有位均已设置,则返回的布尔值是true,否则返回false,
下面的程序说明了bitset :: all()函数。
程序1:
// CPP program to illustrate the
// bitset::all() function
#include
using namespace std;
int main()
{
// Initialization of bitset
bitset<4> b1(string("1100"));
bitset<6> b2(string("111111"));
// Function that checks if all
// the bits are set or not
bool result1 = b1.all();
if (result1)
cout << b1 << " has all bits set"
<< endl;
else
cout << b1 << " does not have all bits set"
<< endl;
// Function that checks if all
// the bits are set or not
bool result2 = b2.all();
if (result2)
cout << b2 << " has all bits set"
<< endl;
else
cout << b2 << " does not have all bits set"
<< endl;
return 0;
}
输出:
1100 does not have all bits set
111111 has all bits set
程式2:
// CPP program to illustrate the
// bitset::all() function
// when the input is as a number
#include
using namespace std;
int main()
{
// Initialization of bitset
bitset<2> b1(3);
bitset<3> b2(5);
// Function that checks if all
// the bits are set or not
bool result1 = b1.all();
if (result1)
cout << b1 << " has all bits set"
<< endl;
else
cout << b1 << " does not have all bits set"
<< endl;
// Function that checks if all
// the bits are set or not
bool result2 = b2.all();
if (result2)
cout << b2 << " has all bits set"
<< endl;
else
cout << b2 << " does not have all bits set"
<< endl;
return 0;
}
输出:
11 has all bits set
101 does not have all bits set
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。