bitset :: reset()是C++ STL中的内置函数,用于重置参数中给定索引处的位。如果未传递任何参数,则所有位都将重置为零。
句法:
reset(int index)
参数:该函数接受参数索引,该索引指示必须将位重置为零的位置。如果未传递任何参数,则位集中的所有位都将重置为零。
返回值:该函数不返回任何内容。
下面的程序说明了bitset :: reset()函数。
程序1:
// CPP program to illustrate the
// bitset::reset() function
#include
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
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++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。