bitset::reset()是C++ STL中的內置函數,用於重置參數中給定索引處的位。如果未傳遞任何參數,則所有位都將重置為零。
用法:
reset(int index)
參數:該函數接受參數索引,該索引指示必須將位重置為零的位置。如果未傳遞任何參數,則位集中的所有位都將重置為零。
返回值:該函數不返回任何內容。
下麵的程序演示了bitset::reset()函數。
示例1:
// CPP program to illustrate the
// bitset::reset() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Initialization of bitset
bitset<4> b1(string("1100"));
bitset<6> b2(string("111111"));
// Function that resets all bits
cout << "Before applying reset() function: "
<< b1 << endl;
b1.reset();
cout << "After applying reset() function: "
<< b1 << endl;
// Function that resets all bits
cout << "Before applying reset() function: "
<< b2 << endl;
b2.reset();
cout << "After applying reset() function: "
<< b2 << endl;
return 0;
}
輸出:
Before applying reset() function: 1100 After applying reset() function: 0000 Before applying reset() function: 111111 After applying reset() function: 000000
示例2:
// CPP program to illustrate the
// bitset::reset() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Initialization of bitset
bitset<4> b1(string("1101"));
bitset<6> b2(string("111111"));
// Function that resets all bits
cout << "Before applying reset() function: "
<< b1 << endl;
b1.reset(2);
cout << "After applying reset(2) function: "
<< b1 << endl;
// Function that resets all bits
cout << "Before applying reset() function: "
<< b2 << endl;
b2.reset(3);
b2.reset(5);
cout << "After applying reset(3) and reset(5) function: "
<< b2 << endl;
return 0;
}
輸出:
Before applying reset() function: 1101 After applying reset(2) function: 1001 Before applying reset() function: 111111 After applying reset(3) and reset(5) function: 010111
相關用法
- C++ bitset set()用法及代碼示例
- C++ bitset all()用法及代碼示例
- C++ bitset any()用法及代碼示例
- C++ bitset none()用法及代碼示例
- C++ bitset size()用法及代碼示例
- C++ bitset::flip()用法及代碼示例
- C++ bitset operator[]用法及代碼示例
- C++ bitset count()用法及代碼示例
- C++ bitset test()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 bitset reset() function in C++ STL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。