Bit Array in C++

前端 未结 8 1078
旧时难觅i
旧时难觅i 2021-02-05 06:09

When working with Project Euler problems I often need large (> 10**7) bit array\'s.

My normal approach is one of:

bool* sieve = new bool[N];

bool sieve[         


        
8条回答
  •  爱一瞬间的悲伤
    2021-02-05 06:57

    For better or for worse, std::vector will use bits instead of bool's, to save space. So just use std::vector like you should have been in the first place.

    If N is a constant, you can use std::bitset.

提交回复
热议问题