當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C++ bitset none()用法及代碼示例


bitset::none()是C++中的內置 STL,如果未設置任何位,則返回True。如果至少設置了一位,則返回False。

用法:

bool count() 

參數:該函數不接受任何參數。


返回值:該函數返回一個布爾值。如果未設置任何布爾值,則為True。如果至少設置了一位,則為False。

下麵的程序演示了bitset::none()函數。

示例1:

// CPP program to illustrate the 
// bitset::none() function 
#include <bits/stdc++.h> 
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; 
}
輸出:
1100 has a minimum of one bit set
000000 has no bits set

示例2:

// CPP program to illustrate the 
// bitset::none() function 
// when the input is a number 
#include <bits/stdc++.h> 
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


相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 bitset none() in C++ STL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。