描述
C++ 函数std::bitset::test()测试是否 Nth位是否设置。
声明
以下是 std::bitset::test() 函数形式 std::bitset 标头的声明。
C++98
bool test (size_t pos) const;
参数
空
返回值
如果 N 返回真th位设置否则为假。
异常
抛出超出范围异常如果pos大于或等于位集大小。
示例
下面的例子展示了 std::bitset::test() 函数的用法。
#include <iostream>
#include <bitset>
using namespace std;
int main(void) {
bitset<4> b(1010);
if (b.test(1))
cout << "1st bit is set." << endl;
if (!b.test(0))
cout << "0th bit is not set." << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果——
1st bit is set. 0th bit is not set.
相关用法
- C++ Bitset to_string()用法及代码示例
- C++ Bitset to_ulong()用法及代码示例
- C++ Bitset to_ullong()用法及代码示例
- C++ Bitset reference()用法及代码示例
- C++ Bitset reset()用法及代码示例
- C++ Bitset hash()用法及代码示例
- C++ Bitset bitset()用法及代码示例
- C++ Bitset all()用法及代码示例
- C++ Bitset set()用法及代码示例
- C++ Bitset any()用法及代码示例
- C++ Bitset none()用法及代码示例
- C++ Bitset flip()用法及代码示例
- C++ Bitset count()用法及代码示例
- C++ Boost.Lexical_Cast用法及代码示例
- C++ unordered_map cbegin用法及代码示例
- C++ map lower_bound()用法及代码示例
- C++ Unordered_multimap reserve()用法及代码示例
- C++ list assign()用法及代码示例
- C++ std::max()用法及代码示例
- C++ std::string::push_back()用法及代码示例
注:本文由纯净天空筛选整理自 C++ Bitset Library - test() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。