Boolean array to hold ASCII characters

Feb 3, 2017 at 6:48pm
I need to make a guesses array (like a vector, but without methods) that holds a Boolean for each ASCII character.
I am new to c++ and have no idea on how to proceed. Please help!
Thank you in advance
Feb 3, 2017 at 7:00pm
like a vector, but without methods

Why is this a requirement?
Feb 3, 2017 at 7:11pm
No, it just need to be a bool array that holds ascii characters
Feb 3, 2017 at 7:30pm
it just need to be a bool array that holds ascii characters

An array of bools can not hold ASCII characters.

You can however, index an array of bools by ASCII characters.
1
2
3
  bool guesses[256];  // An array of bools

  guesses['A'] = true;


Don't forget to initialize the array.

An easier approach is to use the bitset container.
1
2
3
4
5
#include <bitset>

  std::bitset<256> guesses;  // Initialized to false by default

  guesses['A'] = true;

http://www.cplusplus.com/reference/bitset/bitset/








Topic archived. No new replies allowed.