Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string containing bits to vector<bool>

Tags:

c++

I have a std::string of bits like 01001110. How to make it std::vector<bool>?

like image 931
coco_chanel Avatar asked Jun 02 '26 21:06

coco_chanel


1 Answers

std::string bits("10101011110");
std::vector<bool> myVec;
myVec.reserve(bits.size());
for(auto a : bits)
    myVec.push_back(a == '1');
like image 185
NaCl Avatar answered Jun 04 '26 11:06

NaCl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!