A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/cpp/bitset-reset-function-in-c-stl/ below:

bitset reset() function in C++ STL

bitset reset() function in C++ STL

Last Updated : 18 Jun, 2018

bitset::reset()

is a built-in function in C++ STL which resets the bits at the given index in the parameter. If no parameter is passed then all the bits are reset to zero.

Syntax:
reset(int index) 
Parameter:

The function accepts a parameter

index

which signifies the position at which the bit has to be reset to zero. If no parameter is passed, all the bits in the bitset are reset to zero.

Return Value:

The function does not return anything. Below programs illustrates the bitset::reset() function.

Program 1: CPP
// 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;
}
Output:
Before applying reset() function: 1100
After applying reset() function: 0000
Before applying reset() function: 111111
After applying reset() function: 000000
Program 2: CPP
// 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;
}
Output:
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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4