3

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

2
  • 3
    Loop through the string, compare the element to '1', and add the boolean result to your vector. This is a trivial loop, please show a little effort. Commented Dec 8, 2014 at 21:44
  • Just be aware that std::vector<bool> is not a real container. Commented Dec 8, 2014 at 21:44

1 Answer 1

12
std::string bits("10101011110");
std::vector<bool> myVec;
myVec.reserve(bits.size());
for(auto a : bits)
    myVec.push_back(a == '1');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.