By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Can I access single bits from a vector<bitset<N>>?

P: 14
I want to know if this is right:

Expand|Select|Wrap|Line Numbers
  1. if (f%2 == 0) {
  2. bitset<8> bytes;
  3. bytes[0] = node[0][0];
  4. bytes[1] = go[0][0];
  5. bytes[2] = go[0][1];
  6. bytes[3] = go[0][2];
  7. bytes[4] = node[1][0];
  8. bytes[5] = go[1][0];
  9. bytes[6] = go[1][1];
  10. bytes[7] = go[1][2];
  11. out << ios_base::hex << bytes;
  12. node.clear(); go.clear();
  13. }
May 1 '16 #1

✓ answered by weaknessforcats

I can't tell from the code what you want to do. Does the code even compile?

A bitset<> allows you to access and change the state of any bit in the bitset.

You can have a vector of bitsets.

The vector implements an array. The bitset would be an array element. You can use bitset member functions with the array element. So yes, you can access individual bits in a bitset that is a vector element.

Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
I can't tell from the code what you want to do. Does the code even compile?

A bitset<> allows you to access and change the state of any bit in the bitset.

You can have a vector of bitsets.

The vector implements an array. The bitset would be an array element. You can use bitset member functions with the array element. So yes, you can access individual bits in a bitset that is a vector element.
May 2 '16 #2

P: 14
Thank you, I think I found a work around.
May 2 '16 #3

Post your reply

Sign in to post your reply or Sign up for a free account.