Is it possible to create a vector of bits?

I am trying to create a bit vector in C ++. To do this, I tried to try, 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 a program, I get an error message that was bvcnot declared in the area. He goes on to say that the arguments to pattern 1 and 2 are invalid. (1st line). In addition, bvc.push_back(bstemp)an error appears in the line containing the read that the member function is not allowed to use.

+5
source share
2 answers

I have the feeling that you are using pre C ++ 11.

Change this:

vector<bitset<8>> bvc;

:

vector<bitset<8> > bvc;

Otherwise, it is >>parsed as a right-shift operator. This has been "fixed" in C ++ 11.

+13
source

Change vector<bitset<8>> bvcto vector<bitset<8> > bvc. Pay attention to the space. >>- operator.

Yes, a pretty nasty syntax issue.

+4
source

All Articles