bitset :: none()是C++中的内置STL,如果未设置任何位,则返回True。如果至少设置了一位,则返回False。
句法:
bool none()
参数:该函数接受任何参数。
返回值:该函数返回一个布尔值。如果未设置任何布尔值,则布尔值为True 。如果至少设置了一位,则为False 。
下面的程序说明了bitset :: none()函数。
程序1:
C++
// C++ program to illustrate the
// bitset::none() function
#include
using namespace std;
int main()
{
// initialization of bitset
bitset<4> b1(string("1100"));
bitset<6> b2(string("000000"));
// Function to check if none of
// the bits are set or not in b1
bool result1 = b1.none();
if (result1)
cout << b1 << " has no bits set"
<< endl;
else
cout << b1 << " has a minimum of one bit set"
<< endl;
// Function to check if none of
// the bits are set or not in b1
bool result2 = b2.none();
if (result2)
cout << b2 << " has no bits set"
<< endl;
else
cout << b2 << " has a minimum of one bit set"
<< endl;
return 0;
}
C++
// C++ program to illustrate the
// bitset::none() function
// when the input is a number
#include
using namespace std;
int main()
{
// initialization of bitset
bitset<3> b1(4);
bitset<6> b2(0);
// Function to check if none of
// the bits are set or not in b1
bool result1 = b1.none();
if (result1)
cout << b1 << " has no bits set"
<< endl;
else
cout << b1 << " has a minimum of one bit set"
<< endl;
// Function to check if none of
// the bits are set or not in b1
bool result2 = b2.none();
if (result2)
cout << b2 << " has no bits set"
<< endl;
else
cout << b2 << " has a minimum of one bit set"
<< endl;
return 0;
}
输出:
1100 has a minimum of one bit set
000000 has no bits set
程式2:
C++
// C++ program to illustrate the
// bitset::none() function
// when the input is a number
#include
using namespace std;
int main()
{
// initialization of bitset
bitset<3> b1(4);
bitset<6> b2(0);
// Function to check if none of
// the bits are set or not in b1
bool result1 = b1.none();
if (result1)
cout << b1 << " has no bits set"
<< endl;
else
cout << b1 << " has a minimum of one bit set"
<< endl;
// Function to check if none of
// the bits are set or not in b1
bool result2 = b2.none();
if (result2)
cout << b2 << " has no bits set"
<< endl;
else
cout << b2 << " has a minimum of one bit set"
<< endl;
return 0;
}
输出:
100 has a minimum of one bit set
000000 has no bits set
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。