What is the safe way to fill multidimensional array using std::fill?

前端 未结 5 1846
终归单人心
终归单人心 2020-11-30 04:40

Here is what I am using:

class something
{
   char flags[26][80];
} a;

std::fill(&a.flags[0][0], &a.flags[0][0] + 26 * 80, 0);

(Upda

5条回答
  •  既然无缘
    2020-11-30 04:55

    it is safe, a two-dimensional array is an array of arrays. Since an array occupied contiguous storage, so the whole multidimensional thing will too. So yeah, it's OK, safe and portable. Assuming you are NOT asking about style, which is covered by other answers (since you're using flags, I strongly recommend std::vector > myFlags(26))

提交回复
热议问题