Hi!
Does any one know the best war to create a 2dimensional array of booleans.
I know how to create a 1D array using bitset but cant go any further.
Cheers!
PS:can u tell me a little about the bool datatype or any links where i could read up on it.
Hi!
Does any one know the best war to create a 2dimensional array of booleans.
I know how to create a 1D array using bitset but cant go any further.
Cheers!
PS:can u tell me a little about the bool datatype or any links where i could read up on it.
Last edited by eklavya8; 06-27-2008 at 07:50 AM.
Or if you prefer the old, unsafe, C way:Code:#include <boost/array.hpp> boost::array<boost::array<bool, 10>, 10> my2darray;
(PS: For the first, you need boost. You can download it from their website. It's free.)Code:bool my2darray[10][10];
The bool datatype is simply a type which can be true or false. Nothing else.
An array of bool is simply: bool oneD[10]; or bool twoD[10][10];
That's fine if you know the exact size of arrays you need.
If you need an array that can grow, you can use the boost::array as Elysia suggested. Just don't use std::vector<bool> because it's not exactly a vector of bools, and it has some limitations such as not being able to create pointers to individual elements of the vector (this only applies to vector<bool>, not vector<anything else>)
or you could use bool** and create a growable array of bool*, that point to arrays of bools that can grow themselves. You can then access them the same as pBool[5][6]; and you avoid the whole stl nongrowability adn nondirectly addressable problem.
thank you all some really nice stuff learnt.