Is it possible to create a vector of bitsets?

10,437

Solution 1

I have a feeling that you're using pre C++11.

Change this:

vector<bitset<8>> bvc;

to this:

vector<bitset<8> > bvc;

Otherwise, the >> is parsed as the right-shift operator. This was "fixed" in C++11.

Solution 2

Change vector<bitset<8>> bvc to vector<bitset<8> > bvc. Note the space. >> is an operator.

Yes, pretty nasty syntax issue.

Share:
10,437
uyetch
Author by

uyetch

Updated on July 09, 2022

Comments

  • uyetch
    uyetch almost 2 years

    I am trying to create a vector of bitsets in C++. For this, I have tried the attempt as shown in the code snippet below:

    vector<bitset<8>> bvc;
        while (true) {
            bitset<8> bstemp( (long) xtemp );
            if (bstemp.count == y1) {
                bvc.push_back(bstemp);
            }
            if ( xtemp == 0) {
                break;
            }
            xtemp = (xtemp-1) & ntemp;
        }
    

    When I try to compile the program, I get the error that reads that bvc was not declared in the scope. It further tells that the template argument 1 and 2 are invalid. (the 1st line). Also, in the line containing bvc.push_back(bstemp), I am getting an error that reads invalid use of member function.

  • moki
    moki over 9 years
    the term is called Maximal munch if someone is interested for further readings.