Search code examples
c++arraysfill

how do i use fill_n() on the following array?


I have this array

 unsigned char        bit_table_[10][100];

What is the right way to fill it with 0. I tried

std::fill_n(bit_table_,sizeof(bit_table_),0x00);

but vc 2010 flags it as error.


Solution

  • On initialization:

    unsigned char bit_table_[10][100] = {};
    

    If it's a class member, you can initialize it in the constructor, like this:

    MyClass::MyClass()
        :bit_table_()
    {}
    

    Otherwise:

    std::fill_n(*bit_table_,sizeof(bit_table_),0);